Documentation
¶
Index ¶
- Constants
- Variables
- func ChainConnectionGaters(gaters ...connmgr.ConnectionGater) connmgr.ConnectionGater
- func CheckProtocolSupport(_ context.Context, ps peerstore.Peerstore, peerID peer.ID, ...) (bool, error)
- func CompressDialError(err error) error
- func ConvertPeersToMultiAddr(peers []string) ([]string, error)
- func NodeIDFromPeerID(peerID string) (string, error)
- func NodeIDFromPubKey(pubkey crypto.PublicKey) string
- func NodeIDToPubKey(nodeID string) (crypto.PublicKey, error)
- func PeerIDFromPubKey(pubkey crypto.PublicKey) (peer.ID, error)
- func PubKeyFromPeerID(peerID string) (crypto.PublicKey, error)
- func RequirePeerProtos(ctx context.Context, ps peerstore.Peerstore, peer peer.ID, ...) error
- func ResolveHost(addr string) (ip, ipv string, err error)
- type AddrInfo
- type ChainIDGater
- func (g *ChainIDGater) InterceptAccept(connAddrs network.ConnMultiaddrs) bool
- func (g *ChainIDGater) InterceptAddrDial(p peer.ID, addr multiaddr.Multiaddr) bool
- func (g *ChainIDGater) InterceptPeerDial(p peer.ID) bool
- func (g *ChainIDGater) InterceptSecured(dir network.Direction, p peer.ID, conn network.ConnMultiaddrs) bool
- func (g *ChainIDGater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)
- type Config
- type Connector
- type GateOpt
- type OutboundWhitelistGater
- func (g *OutboundWhitelistGater) InterceptAccept(connAddrs network.ConnMultiaddrs) bool
- func (g *OutboundWhitelistGater) InterceptAddrDial(p peer.ID, addr multiaddr.Multiaddr) bool
- func (g *OutboundWhitelistGater) InterceptPeerDial(p peer.ID) bool
- func (g *OutboundWhitelistGater) InterceptSecured(dir network.Direction, p peer.ID, conn network.ConnMultiaddrs) bool
- func (g *OutboundWhitelistGater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)
- type PeerIDStringer
- type PeerInfo
- type PeerMan
- func (pm *PeerMan) Allow(p peer.ID)
- func (pm *PeerMan) AllowPersistent(p peer.ID)
- func (pm *PeerMan) Allowed() []peer.ID
- func (pm *PeerMan) AllowedPersistent() []peer.ID
- func (pm *PeerMan) Connect(ctx context.Context, info AddrInfo) error
- func (pm *PeerMan) Connected(net network.Network, conn network.Conn)
- func (pm *PeerMan) ConnectedPeers() []PeerInfo
- func (pm *PeerMan) Disallow(p peer.ID)
- func (pm *PeerMan) Disconnected(net network.Network, conn network.Conn)
- func (pm *PeerMan) DiscoveryStreamHandler(s network.Stream)
- func (pm *PeerMan) FindPeers(ctx context.Context, ns string, opts ...discovery.Option) (<-chan peer.AddrInfo, error)
- func (pm *PeerMan) IsAllowed(p peer.ID) bool
- func (pm *PeerMan) KnownPeers() (all, connected, disconnected []PeerInfo)
- func (pm *PeerMan) Listen(network.Network, multiaddr.Multiaddr)
- func (pm *PeerMan) ListenClose(network.Network, multiaddr.Multiaddr)
- func (pm *PeerMan) PrintKnownPeers()
- func (pm *PeerMan) RequestPeers(ctx context.Context, peerID peer.ID) ([]PeerInfo, error)
- func (pm *PeerMan) Start(ctx context.Context) error
- type PersistentPeerInfo
- type RemotePeersFn
- type WhitelistGater
- func (g *WhitelistGater) Allow(p peer.ID)
- func (g *WhitelistGater) Allowed() []peer.ID
- func (g *WhitelistGater) Disallow(p peer.ID) bool
- func (g *WhitelistGater) InterceptAccept(connAddrs network.ConnMultiaddrs) bool
- func (g *WhitelistGater) InterceptAddrDial(p peer.ID, addr multiaddr.Multiaddr) bool
- func (g *WhitelistGater) InterceptPeerDial(p peer.ID) bool
- func (g *WhitelistGater) InterceptSecured(dir network.Direction, p peer.ID, conn network.ConnMultiaddrs) bool
- func (g *WhitelistGater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)
- func (g *WhitelistGater) IsAllowed(p peer.ID) bool
Constants ¶
const ( ProtocolIDDiscover protocol.ID = "/kwil/discovery/1.0.0" // the PEX protocol that all peers support, and is the only real protocol that crawlers support other than the dummy ProtocolIDCrawler ProtocolIDCrawler protocol.ID = "/kwil/crawler/1.0.0" // dummy to identify a crawler that should not stay connected ProtocolIDPrefixChainID protocol.ID = "/kwil/chain/1.0.0/" )
Variables ¶
var ErrNoRecordedAddress = errors.New("no address for peer in peerstore")
ErrNoRecordedAddress is returned when a peer is known or even connected, but there are no addresses available for it. This can be case when an incoming connection is established from a peer that does not have a routable IP address on which they can accept incoming connections.
Functions ¶
func ChainConnectionGaters ¶
func ChainConnectionGaters(gaters ...connmgr.ConnectionGater) connmgr.ConnectionGater
func CheckProtocolSupport ¶
func CompressDialError ¶
func ConvertPeersToMultiAddr ¶
ConvertPeersToMultiAddr convert a peer from pubkeyHex#keyTypeInt@ip:port to /ip4/ip/tcp/port/p2p/peerID
func NodeIDFromPeerID ¶
Convert from go-libp2p's peer.ID format to Kwil's node ID format.
func NodeIDFromPubKey ¶
func PeerIDFromPubKey ¶
PeerIDFromPubKey converts a pubkey to a peer ID string.
func PubKeyFromPeerID ¶
PubKeyFromPeerID tries to decode the pubkey from a peer ID string. This will only work if the peer ID is an "identity" multihash.
func RequirePeerProtos ¶
func ResolveHost ¶
Types ¶
type ChainIDGater ¶
type ChainIDGater struct {
// contains filtered or unexported fields
}
func NewChainIDGater ¶
func NewChainIDGater(chainID string, opts ...GateOpt) *ChainIDGater
func (*ChainIDGater) InterceptAccept ¶
func (g *ChainIDGater) InterceptAccept(connAddrs network.ConnMultiaddrs) bool
func (*ChainIDGater) InterceptAddrDial ¶
func (*ChainIDGater) InterceptPeerDial ¶
func (g *ChainIDGater) InterceptPeerDial(p peer.ID) bool
func (*ChainIDGater) InterceptSecured ¶
func (g *ChainIDGater) InterceptSecured(dir network.Direction, p peer.ID, conn network.ConnMultiaddrs) bool
func (*ChainIDGater) InterceptUpgraded ¶
func (g *ChainIDGater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)
type OutboundWhitelistGater ¶
OutboundWhitelistGater is to prevent dialing out to peers that are not explicitly allowed by an application provided filter function. This exists in part to prevent other modules such as the DHT and gossipsub from dialing out to peers that are not explicitly allowed (e.g. already connected or added by the application).
func (*OutboundWhitelistGater) InterceptAccept ¶
func (g *OutboundWhitelistGater) InterceptAccept(connAddrs network.ConnMultiaddrs) bool
func (*OutboundWhitelistGater) InterceptAddrDial ¶
func (*OutboundWhitelistGater) InterceptPeerDial ¶
func (g *OutboundWhitelistGater) InterceptPeerDial(p peer.ID) bool
func (*OutboundWhitelistGater) InterceptSecured ¶
func (g *OutboundWhitelistGater) InterceptSecured(dir network.Direction, p peer.ID, conn network.ConnMultiaddrs) bool
func (*OutboundWhitelistGater) InterceptUpgraded ¶
func (g *OutboundWhitelistGater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)
type PeerIDStringer ¶
type PeerIDStringer string
PeerIDStringer provides lazy lazy conversion of a libp2p peer ID into a Kwil node ID, which is a public key with a type suffix.
func (PeerIDStringer) String ¶
func (p PeerIDStringer) String() string
type PeerMan ¶
type PeerMan struct {
// contains filtered or unexported fields
}
func NewPeerMan ¶
func (*PeerMan) AllowPersistent ¶
func (*PeerMan) AllowedPersistent ¶
func (*PeerMan) ConnectedPeers ¶
ConnectedPeers returns a list of peer info for all connected peers.
func (*PeerMan) Disconnected ¶
Disconnected is triggered when a peer disconnects
func (*PeerMan) DiscoveryStreamHandler ¶
DiscoveryStreamHandler sends a list of peer addresses on the stream. This implements the receiving side of ProtocolIDDiscover.
func (*PeerMan) KnownPeers ¶
KnownPeers returns a list of peer info for all known peers (connected or just in peer store).
func (*PeerMan) PrintKnownPeers ¶
func (pm *PeerMan) PrintKnownPeers()
func (*PeerMan) RequestPeers ¶
RequestPeers initiates the ProtocolIDDiscover stream.
type PersistentPeerInfo ¶
type PersistentPeerInfo struct {
NodeID string `json:"id"` // "node ID" (pubkeybytes#keytype)
Addrs []multiaddr.Multiaddr `json:"addrs"`
Protos []protocol.ID `json:"protos"`
Whitelisted bool `json:"whitelisted"`
}
func (PersistentPeerInfo) MarshalJSON ¶
func (p PersistentPeerInfo) MarshalJSON() ([]byte, error)
func (*PersistentPeerInfo) UnmarshalJSON ¶
func (p *PersistentPeerInfo) UnmarshalJSON(data []byte) error
type RemotePeersFn ¶
type WhitelistGater ¶
type WhitelistGater struct {
// contains filtered or unexported fields
}
WhitelistGater is a libp2p connmgr.ConnectionGater implementation to enforce a peer whitelist.
func NewWhitelistGater ¶
func NewWhitelistGater(allowed []peer.ID, opts ...GateOpt) *WhitelistGater
func (*WhitelistGater) Allow ¶
func (g *WhitelistGater) Allow(p peer.ID)
Allow adds a peer to the whitelist.
func (*WhitelistGater) Allowed ¶
func (g *WhitelistGater) Allowed() []peer.ID
Allowed returns the list of peers in the whitelist.
func (*WhitelistGater) Disallow ¶
func (g *WhitelistGater) Disallow(p peer.ID) bool
Disallow removes a peer from the whitelist and returns true if the whitelistGater is enabled and the peer was removed.
func (*WhitelistGater) InterceptAccept ¶
func (g *WhitelistGater) InterceptAccept(connAddrs network.ConnMultiaddrs) bool
func (*WhitelistGater) InterceptAddrDial ¶
func (*WhitelistGater) InterceptPeerDial ¶
func (g *WhitelistGater) InterceptPeerDial(p peer.ID) bool
func (*WhitelistGater) InterceptSecured ¶
func (g *WhitelistGater) InterceptSecured(dir network.Direction, p peer.ID, conn network.ConnMultiaddrs) bool
func (*WhitelistGater) InterceptUpgraded ¶
func (g *WhitelistGater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)