-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p: add peer name to networking component contexts #652
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
"github.com/obolnetwork/charon/core" | ||
pbv1 "github.com/obolnetwork/charon/core/corepb/v1" | ||
"github.com/obolnetwork/charon/core/qbft" | ||
"github.com/obolnetwork/charon/p2p" | ||
) | ||
|
||
// transport encapsulates receiving and broadcasting for a consensus instance/duty. | ||
|
@@ -115,6 +116,7 @@ func (t *transport) Broadcast(ctx context.Context, typ qbft.MsgType, duty core.D | |
continue | ||
} | ||
|
||
ctx = context.WithValue(ctx, p2p.PeerCtxKey, p2p.PeerName(t.component.tcpNode.ID())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is broadcasting, this ticket is for receiving. |
||
err := send(ctx, t.component.tcpNode, p.ID, msg.ToConsensusMsg()) | ||
if err != nil { | ||
log.Warn(ctx, "Failed sending message", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ import ( | |
"github.com/obolnetwork/charon/app/errors" | ||
) | ||
|
||
const PeerCtxKey = "peer" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it okay to let other packages depend on p2p just for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nah, this is not worth it. We use string literals in many places without needing to add |
||
|
||
// Peer represents a peer in the libp2p network, either a charon node or a relay. | ||
type Peer struct { | ||
// ENR defines the networking information of the peer. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use the
log
package for this to work:ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(s.Conn().RemotePeer()))