Skip to content

Commit

Permalink
fix: adapt for new changes with peer.IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
oykmnk committed Sep 8, 2019
1 parent 178dae9 commit 9db2bc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions pkg/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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
}

Expand Down

0 comments on commit 9db2bc5

Please sign in to comment.