From 9db2bc5a016f29dbc08b4b902854f2ac49ce30f7 Mon Sep 17 00:00:00 2001 From: alyakimenko Date: Sun, 8 Sep 2019 10:05:27 +0300 Subject: [PATCH] fix: adapt for new changes with peer.IDs --- cmd/main.go | 2 +- pkg/handler.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index b67ebed..ed81d9a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -201,7 +201,7 @@ func main() { // Set global PubSub object pubSub = pb - handler = pkg.NewHandler(pb, serviceTopic, multiaddress, &networkTopics) + handler = pkg.NewHandler(pb, serviceTopic, host.ID(), &networkTopics) // Randezvous string = service tag // Disvover all peers with our service (all ms devices) diff --git a/pkg/handler.go b/pkg/handler.go index 4155fe2..7ec842b 100644 --- a/pkg/handler.go +++ b/pkg/handler.go @@ -18,8 +18,8 @@ type Handler struct { pb *pubsub.PubSub serviceTopic string networkTopics mapset.Set - identityMap map[string]string - multiaddress string + identityMap map[peer.ID]string + peerID peer.ID matrixID string PbMutex sync.Mutex } @@ -31,13 +31,13 @@ type TextMessage struct { From peer.ID } -func NewHandler(pb *pubsub.PubSub, serviceTopic, multiaddress string, networkTopics *mapset.Set) Handler { +func NewHandler(pb *pubsub.PubSub, serviceTopic string, peerID peer.ID, networkTopics *mapset.Set) Handler { return Handler{ pb: pb, serviceTopic: serviceTopic, networkTopics: *networkTopics, - identityMap: make(map[string]string), - multiaddress: multiaddress, + identityMap: make(map[peer.ID]string), + peerID: peerID, } } @@ -98,8 +98,8 @@ func (h *Handler) HandleIncomingMessage(topic string, msg pubsub.Message, handle Body: "", Flag: api.FlagIdentityResponse, }, - Multiaddress: h.multiaddress, - MatrixID: h.matrixID, + PeerID: h.peerID, + MatrixID: h.matrixID, } sendData, err := json.Marshal(respond) if err != nil { @@ -118,7 +118,7 @@ func (h *Handler) HandleIncomingMessage(topic string, msg pubsub.Message, handle log.Println("Error occurred during unmarshalling the message data from IdentityResponse") return } - h.identityMap[respond.Multiaddress] = respond.MatrixID + h.identityMap[respond.PeerID] = respond.MatrixID default: log.Printf("\nUnknown message type: %#x\n", message.Flag) } @@ -130,7 +130,7 @@ func (h *Handler) SetMatrixID(matrixID string) { } // Returns copy of handler's identity map ([multiaddress]=>[matrixID]) -func (h *Handler) GetIdentityMap() map[string]string { +func (h *Handler) GetIdentityMap() map[peer.ID]string { return h.identityMap }