ceremonyclient/node/internal/grpc/peer_id.go
Cassandra Heart dbd95bd9e9
v2.1.0 (#439)
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete

* 2.1.0 main node rollup
2025-09-30 02:48:15 -05:00

27 lines
656 B
Go

package grpc
import (
"context"
"github.com/libp2p/go-libp2p/core/peer"
)
type peerIDKeyType struct{}
var peerIDKey peerIDKeyType
// PeerIDFromContext returns the peer.ID of the remote peer from the given
// context.
func PeerIDFromContext(ctx context.Context) (peer.ID, bool) {
if peerID, ok := ctx.Value(peerIDKey).(peer.ID); ok {
return peerID, true
}
return "", false
}
// NewContextWithPeerID returns a new context with the given peer.ID.
// This method is meant to be used only in unit testing contexts.
func NewContextWithPeerID(ctx context.Context, peerID peer.ID) context.Context {
return context.WithValue(ctx, peerIDKey, peerID)
}