github.com/MetalBlockchain/metalgo@v1.11.9/network/peer/network.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package peer 5 6 import ( 7 "github.com/MetalBlockchain/metalgo/ids" 8 "github.com/MetalBlockchain/metalgo/utils/bloom" 9 "github.com/MetalBlockchain/metalgo/utils/ips" 10 ) 11 12 // Network defines the interface that is used by a peer to help establish a well 13 // connected p2p network. 14 type Network interface { 15 // Connected is called by the peer once the handshake is finished. 16 Connected(peerID ids.NodeID) 17 18 // AllowConnection enables the network is signal to the peer that its 19 // connection is no longer desired and should be terminated. 20 AllowConnection(peerID ids.NodeID) bool 21 22 // Track allows the peer to notify the network of potential new peers to 23 // connect to. 24 Track(ips []*ips.ClaimedIPPort) error 25 26 // Disconnected is called when the peer finishes shutting down. It is not 27 // guaranteed that [Connected] was called for the provided peer. However, it 28 // is guaranteed that [Connected] will not be called after [Disconnected] 29 // for a given [Peer] object. 30 Disconnected(peerID ids.NodeID) 31 32 // KnownPeers returns the bloom filter of the known peers. 33 KnownPeers() (bloomFilter []byte, salt []byte) 34 35 // Peers returns peers that are not known. 36 Peers( 37 peerID ids.NodeID, 38 knownPeers *bloom.ReadFilter, 39 peerSalt []byte, 40 ) []*ips.ClaimedIPPort 41 }