diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 00d8c4b..2be6181 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -18,8 +18,6 @@ import ( "sync" "time" - "cwtch.im/cwtch/model/constants" - "cwtch.im/cwtch/event" "cwtch.im/cwtch/model" "cwtch.im/cwtch/model/attr" @@ -599,7 +597,7 @@ func (cp *cwtchPeer) StartGroup(name string, server string) (int, error) { // Returns the onion of the new server if added // TODO in the future this function should also integrate with a trust provider to validate the key bundle. // Status: Ready for 1.5 -func (cp *cwtchPeer) AddServer(serverSpecification string) error { +func (cp *cwtchPeer) AddServer(serverSpecification string) (string, error) { // This confirms that the server did at least sign the bundle keyBundle, err := model.DeserializeAndVerify([]byte(serverSpecification)) if err != nil { @@ -623,7 +621,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error { if conversationInfo == nil { _, err := cp.NewContactConversation(onion, model.DefaultP2PAccessControl(), true) if err != nil { - return err + return "", err } } @@ -635,7 +633,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error { if exists { if val != v { // this is inconsistent! - return model.InconsistentKeyBundleError + return "", model.InconsistentKeyBundleError } } // we haven't seen this key associated with the server before @@ -647,13 +645,12 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error { cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(k)), v) } cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(string(model.BundleType))), serverSpecification) - + return onion, err } else { - return err + return "", err } - return nil } - return nil + return "", model.InconsistentKeyBundleError } // GetServers returns an unordered list of servers @@ -775,7 +772,7 @@ const importBundlePrefix = "importBundle" func (cp *cwtchPeer) ImportBundle(importString string) error { if tor.IsValidHostname(importString) { - _,err := cp.NewContactConversation(importString, model.DefaultP2PAccessControl(), true) + _, err := cp.NewContactConversation(importString, model.DefaultP2PAccessControl(), true) if err == nil { return ConstructResponse(importBundlePrefix, "success") } else { @@ -795,7 +792,7 @@ func (cp *cwtchPeer) ImportBundle(importString string) error { // Server Key Bundles are prefixed with bundle, err := base64.StdEncoding.DecodeString(importString[len(serverPrefix):]) if err == nil { - if err = cp.AddServer(string(bundle)); err != nil { + if _, err = cp.AddServer(string(bundle)); err != nil { return ConstructResponse(importBundlePrefix, err.Error()) } return ConstructResponse(importBundlePrefix, "success") @@ -1167,7 +1164,7 @@ func (cp *cwtchPeer) attemptInsertOrAcknowledgeLegacyGroupConversation(conversat } else { cp.mutex.Lock() cp.storage.InsertMessage(conversationID, 0, dm.Text, model.Attributes{constants.AttrAck: constants.True, "PreviousSignature": base64.StdEncoding.EncodeToString(dm.PreviousMessageSig), constants.AttrAuthor: dm.Onion, constants.AttrSentTimestamp: time.Unix(int64(dm.Timestamp), 0).Format(time.RFC3339Nano)}, signature, model.CalculateContentHash(dm.Onion, dm.Text)) - newTotal,_ := cp.storage.GetChannelMessageCount(conversationID, 0) + newTotal, _ := cp.storage.GetChannelMessageCount(conversationID, 0) cp.mutex.Unlock() cp.eventBus.Publish(event.NewEvent(event.NewMessageFromGroup, map[event.Field]string{event.ConversationID: strconv.Itoa(conversationID), event.TimestampSent: time.Unix(int64(dm.Timestamp), 0).Format(time.RFC3339Nano), event.RemotePeer: dm.Onion, event.Index: strconv.Itoa(newTotal)})) return nil diff --git a/peer/profile_interface.go b/peer/profile_interface.go index eefd542..3546bfc 100644 --- a/peer/profile_interface.go +++ b/peer/profile_interface.go @@ -40,7 +40,7 @@ type ModifyGroups interface { // ModifyServers provides write-only access to servers type ModifyServers interface { - AddServer(string) error + AddServer(string) (string, error) ResyncServer(onion string) error } diff --git a/testing/cwtch_peer_server_integration_test.go b/testing/cwtch_peer_server_integration_test.go index 1904917..adc3bd8 100644 --- a/testing/cwtch_peer_server_integration_test.go +++ b/testing/cwtch_peer_server_integration_test.go @@ -208,7 +208,7 @@ func TestCwtchPeerIntegration(t *testing.T) { // Simulate Alice Creating a Group fmt.Println("Alice joining server...") - if err := alice.AddServer(string(serverKeyBundle)); err != nil { + if _, err := alice.AddServer(string(serverKeyBundle)); err != nil { t.Fatalf("Failed to Add Server Bundle %v", err) }