Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 46f6172

Browse files
committed
Listening to websocket for incomings
Fix peer ID Fix peer ID
1 parent 8cdce94 commit 46f6172

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

core/net.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (n *OpenBazaarNode) SendOfflineMessage(p peer.ID, k *libp2p.PubKey, m *pb.M
106106
// Base64 encode
107107
encodedCipherText := base64.StdEncoding.EncodeToString(relayciphertext)
108108

109-
n.WebRelayManager.SendRelayMessage(encodedCipherText, p.String())
109+
n.WebRelayManager.SendRelayMessage(encodedCipherText, p.Pretty())
110110

111111
// TODO: this function blocks if the recipient's public key is not on the local machine
112112
ciphertext, cerr := n.EncryptMessage(p, k, messageBytes)

net/web_relay_manager.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func connectToServer(relay string, sender string) (*websocket.Conn, error) {
8686

8787
socketmessage, _ := json.Marshal(typedmessage)
8888

89+
fmt.Println(string(socketmessage))
8990
// Connect to websocket server
9091
fmt.Printf("Connecting to relay server: %s\n", relay)
9192

@@ -103,6 +104,25 @@ func connectToServer(relay string, sender string) (*websocket.Conn, error) {
103104

104105
fmt.Printf("Successfully connected and subscribed to: %s\n", relay)
105106

107+
go func() {
108+
for {
109+
// read in a message
110+
_, p, err := c.ReadMessage()
111+
if err != nil {
112+
fmt.Println(err)
113+
//return nil, err
114+
}
115+
// print out that message for clarity
116+
fmt.Printf("Received incoming message from relay: %s\n", string(p))
117+
118+
//if err := c.WriteMessage(messageType, p); err != nil {
119+
// fmt.Println(err)
120+
// //return nil, err
121+
//}
122+
123+
}
124+
}()
125+
106126
return c, nil
107127
}
108128

0 commit comments

Comments
 (0)