mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 18:37:26 +08:00
* 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
27 lines
656 B
Go
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)
|
|
}
|