Skip to content

Commit fe12566

Browse files
committed
log peer id in multiaddrs
1 parent 776ba27 commit fe12566

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

go-server/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func main() {
205205

206206
LogMsgf("PeerID: %s", h.ID().String())
207207
for _, addr := range h.Addrs() {
208-
LogMsgf("Listening on: %s", addr.String())
208+
LogMsgf("Listening on: %s/p2p/%s", addr.String(), h.ID())
209209
}
210210

211211
// draw the UI

go-server/ui.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/gdamore/tcell/v2"
10+
"github.com/libp2p/go-libp2p/core/peer"
1011
"github.com/rivo/tview"
1112
)
1213

@@ -20,7 +21,7 @@ type ChatUI struct {
2021
peersList *tview.TextView
2122

2223
msgW io.Writer
23-
sysW io.Writer
24+
sysW io.Writer
2425
inputCh chan string
2526
doneCh chan struct{}
2627
}
@@ -151,7 +152,8 @@ func (ui *ChatUI) refreshPeers() {
151152
// displayChatMessage writes a ChatMessage from the room to the message window,
152153
// with the sender's nick highlighted in green.
153154
func (ui *ChatUI) displayChatMessage(cm *ChatMessage) {
154-
prompt := withColor("green", fmt.Sprintf("<%s>:", cm.SenderNick))
155+
p := peer.ID(cm.SenderID)
156+
prompt := withColor("green", fmt.Sprintf("<%s>:", shortID(p)))
155157
fmt.Fprintf(ui.msgW, "%s %s\n", prompt, cm.Message)
156158
}
157159

0 commit comments

Comments
 (0)