@@ -18,6 +18,7 @@ import (
18
18
19
19
ipfslog "github.com/ipfs/go-log/v2"
20
20
pubsub "github.com/libp2p/go-libp2p-pubsub"
21
+ "github.com/libp2p/go-libp2p/core/peer"
21
22
"go.uber.org/zap"
22
23
"google.golang.org/protobuf/proto"
23
24
)
@@ -68,6 +69,7 @@ func main() {
68
69
localContext , localCancel := context .WithCancel (rootCtx )
69
70
defer localCancel ()
70
71
hbReceived := false
72
+ var addrInfo peer.AddrInfo
71
73
observationsReceived := 0
72
74
components := p2p .DefaultComponents ()
73
75
components .Port = p2pPort
@@ -108,8 +110,11 @@ func main() {
108
110
switch m := msg .Message .(type ) {
109
111
case * gossipv1.GossipMessage_SignedHeartbeat :
110
112
logger .Debug ("received heartbeat" )
111
- if ! hbReceived && bytes .Equal (m .SignedHeartbeat .GuardianAddr , guardianPubKey ) {
112
- hbReceived = true
113
+ if bytes .Equal (m .SignedHeartbeat .GuardianAddr , guardianPubKey ) {
114
+ addrInfo = host .Peerstore ().PeerInfo (envelope .GetFrom ())
115
+ if ! hbReceived {
116
+ hbReceived = true
117
+ }
113
118
}
114
119
case * gossipv1.GossipMessage_SignedObservation :
115
120
logger .Debug ("received observation" )
@@ -135,7 +140,7 @@ func main() {
135
140
logger .Info ("local context cancelled" )
136
141
137
142
if hbReceived {
138
- fmt .Println ("✅ guardian heartbeat received" )
143
+ fmt .Println ("✅ guardian heartbeat received" , addrInfo . String () )
139
144
} else {
140
145
fmt .Println ("❌ NO HEARTBEAT RECEIVED" )
141
146
}
0 commit comments