From 178dae995f9e0f225a61565fd9d9a2c3fdb67b54 Mon Sep 17 00:00:00 2001 From: alyakimenko Date: Sun, 8 Sep 2019 09:56:35 +0300 Subject: [PATCH 1/3] feat: change field type from multiaddress to peer.ID --- api/protocol.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/protocol.go b/api/protocol.go index ff99642..3070645 100644 --- a/api/protocol.go +++ b/api/protocol.go @@ -1,5 +1,7 @@ package api +import "github.com/libp2p/go-libp2p-core/peer" + /* Flags: - 0x0: Generic message @@ -33,6 +35,6 @@ type GetTopicsRespondMessage struct { // Flag: 0x4 type GetIdentityRespondMessage struct { BaseMessage - Multiaddress string `json:"multiaddress"` - MatrixID string `json:"matrix_id"` + PeerID peer.ID `json:"peer_id"` + MatrixID string `json:"matrix_id"` } From 9db2bc5a016f29dbc08b4b902854f2ac49ce30f7 Mon Sep 17 00:00:00 2001 From: alyakimenko Date: Sun, 8 Sep 2019 10:05:27 +0300 Subject: [PATCH 2/3] 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 } From a18e627d0c92f8c47d1531a81125e9818b03704f Mon Sep 17 00:00:00 2001 From: alyakimenko Date: Sun, 8 Sep 2019 10:07:43 +0300 Subject: [PATCH 3/3] doc: update documentation for GetIdentityMap method --- pkg/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/handler.go b/pkg/handler.go index 7ec842b..19cb428 100644 --- a/pkg/handler.go +++ b/pkg/handler.go @@ -129,7 +129,7 @@ func (h *Handler) SetMatrixID(matrixID string) { h.matrixID = matrixID } -// Returns copy of handler's identity map ([multiaddress]=>[matrixID]) +// Returns copy of handler's identity map ([peer.ID]=>[matrixID]) func (h *Handler) GetIdentityMap() map[peer.ID]string { return h.identityMap }