Skip to content

Commit

Permalink
Release v1.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
oykmnk authored Sep 8, 2019
2 parents c18786a + a18e627 commit 1770a93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions api/protocol.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package api

import "github.com/libp2p/go-libp2p-core/peer"

/*
Flags:
- 0x0: Generic message
Expand Down Expand Up @@ -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"`
}
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
20 changes: 10 additions & 10 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 @@ -129,8 +129,8 @@ func (h *Handler) SetMatrixID(matrixID string) {
h.matrixID = matrixID
}

// Returns copy of handler's identity map ([multiaddress]=>[matrixID])
func (h *Handler) GetIdentityMap() map[string]string {
// Returns copy of handler's identity map ([peer.ID]=>[matrixID])
func (h *Handler) GetIdentityMap() map[peer.ID]string {
return h.identityMap
}

Expand Down

0 comments on commit 1770a93

Please sign in to comment.