Documentation
¶
Index ¶
- Constants
- func InitPeer(infos NetworkInfos, prot string, ctx context.Context) (host.Host, error)
- type HttpTracker
- func (t HttpTracker) AddPeer(peerID, peerIP string, peerPort int) error
- func (t HttpTracker) IP() string
- func (t HttpTracker) Peers() ([]PeerInfos, error)
- func (t HttpTracker) Ping() error
- func (t HttpTracker) Port() int
- func (t HttpTracker) RemovePeer(pid string) error
- func (t HttpTracker) URL() string
- type Network
- type NetworkInfos
- type P2PNetwork
- func (n *P2PNetwork) AddAddrs(remote PeerID, addrs []ma.Multiaddr)
- func (n *P2PNetwork) Addrs() []ma.Multiaddr
- func (n *P2PNetwork) Close() error
- func (n *P2PNetwork) Connect(id PeerID, protocol string) (*WrappedStream, error)
- func (n *P2PNetwork) Disconnect(remote PeerID) error
- func (n *P2PNetwork) FirstPeer() (PeerID, error)
- func (n *P2PNetwork) ID() PeerID
- func (n *P2PNetwork) Peers() []PeerID
- func (n *P2PNetwork) RequestFileToPeers(file storage.FileHash, remoteStorage storage.PeerStorage) (int, error)
- func (n *P2PNetwork) SendDatagram(d *protocol.Datagram, pid PeerID) (err error)
- func (n *P2PNetwork) SetDatagramHandler(handler func(*protocol.Datagram, PeerID) error)
- type P2PPeerID
- type PeerID
- type PeerInfos
- type Tracker
- type WrappedStream
Constants ¶
const (
TrackerFileName = "trackers.p2p"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HttpTracker ¶
type HttpTracker struct { Secure bool Tracker NetworkInfos }
func (HttpTracker) AddPeer ¶
func (t HttpTracker) AddPeer(peerID, peerIP string, peerPort int) error
AddPeer: Request Tracker to add a peer
func (HttpTracker) IP ¶
func (t HttpTracker) IP() string
IP: Return Tracker NetworkInfos.Ip (Ex: <192.168.0.31>)
func (HttpTracker) Peers ¶
func (t HttpTracker) Peers() ([]PeerInfos, error)
Peers: Get peers from Tracker.
func (HttpTracker) Port ¶
func (t HttpTracker) Port() int
Port: Return Tracker NetworkInfos.NWPort (Ex: <5001>)
func (HttpTracker) RemovePeer ¶
func (t HttpTracker) RemovePeer(pid string) error
AddPeer: Request Tracker to remove a peer
func (HttpTracker) URL ¶
func (t HttpTracker) URL() string
URL: Return Tracker URL like (Ex: <192.168.0.31:5001>)
type Network ¶
type Network interface { // SendDatagram sends a datagram to the remote peer SendDatagram(d *protocol.Datagram, remote PeerID) error // Connect connects to the remote peer and creates any io resources necessary for the connection Connect(remote PeerID, protocol string) (*WrappedStream, error) // Disconnect disconnects from the remote peer and destroys any io resources created for the connection Disconnect(remote PeerID) error // ID returns the ID of this peer ID() PeerID // SetDatagramHandler sets the function that will be called on receipt of a new datagram // f gets called every time a new Datagram is received. SetDatagramHandler(f func(*protocol.Datagram, PeerID) error) // AddAddrs adds multiaddresses for the remote peer to this peer's store AddAddrs(id PeerID, addrs []ma.Multiaddr) // Addrs returns multiaddresses for this peer Addrs() []ma.Multiaddr // Close close the network Close() error // Peers return all connected peers Peers() []PeerID // RequestFileToPeers launch Have request to connected peers and return file size. RequestFileToPeers(file storage.FileHash, remoteStorage storage.PeerStorage) (int, error) }
Network handles interactions with the underlying protocol
type NetworkInfos ¶
func NewNetworkInfos ¶
func NewNetworkInfos(ip string, port int) NetworkInfos
func (*NetworkInfos) IP ¶
func (n *NetworkInfos) IP() string
func (*NetworkInfos) Port ¶
func (n *NetworkInfos) Port() int
func (*NetworkInfos) PubIP ¶
func (n *NetworkInfos) PubIP() string
func (*NetworkInfos) URL ¶
func (n *NetworkInfos) URL() string
type P2PNetwork ¶
func NewLibp2pNetwork ¶
func NewLibp2pNetwork(infos NetworkInfos, prot string) (*P2PNetwork, error)
func (*P2PNetwork) Addrs ¶
func (n *P2PNetwork) Addrs() []ma.Multiaddr
func (*P2PNetwork) Close ¶
func (n *P2PNetwork) Close() error
func (*P2PNetwork) Connect ¶
func (n *P2PNetwork) Connect(id PeerID, protocol string) (*WrappedStream, error)
Connect creates a stream from p to the peer at id and sets a stream handler func (n *P2PNetwork) Connect(id PeerID) (*WrappedStream, error) {
func (*P2PNetwork) Disconnect ¶
func (n *P2PNetwork) Disconnect(remote PeerID) error
func (*P2PNetwork) FirstPeer ¶
func (n *P2PNetwork) FirstPeer() (PeerID, error)
func (*P2PNetwork) ID ¶
func (n *P2PNetwork) ID() PeerID
func (*P2PNetwork) Peers ¶
func (n *P2PNetwork) Peers() []PeerID
func (*P2PNetwork) RequestFileToPeers ¶
func (n *P2PNetwork) RequestFileToPeers(file storage.FileHash, remoteStorage storage.PeerStorage) (int, error)
func (*P2PNetwork) SendDatagram ¶
func (n *P2PNetwork) SendDatagram(d *protocol.Datagram, pid PeerID) (err error)
func (*P2PNetwork) SetDatagramHandler ¶
func (n *P2PNetwork) SetDatagramHandler(handler func(*protocol.Datagram, PeerID) error)
type Tracker ¶
type Tracker interface { IP() string URL() string Port() int Ping() error AddPeer(peerID, peerIP string, peerPort int) error Peers() ([]PeerInfos, error) RemovePeer(id string) error }
func NewHttpTracker ¶
NewHttpTracker Create a new htttp tracker Allows Node to request permanent otherPeers from http server
func ParseTrackerInfos ¶
type WrappedStream ¶
type WrappedStream struct { Stream inet.Stream Enc *json.Encoder Dec *json.Decoder W *bufio.Writer R *bufio.Reader }
WrappedStream wraps a libp2p stream. We encode/decode whenever we write/read from a stream, so we can just carry the encoders and bufios with us
func WrapStream ¶
func WrapStream(s inet.Stream) *WrappedStream
WrapStream takes a stream and complements it with r/w bufios and decoder/encoder. In order to write raw storage to the stream we can use wrap.w.Write(). To encode something into it we can wrap.enc.Encode(). Finally, we should wrap.w.Flush() to actually send the storage. Handling incoming storage works similarly with wrap.r.Read() for raw-reading and wrap.dec.Decode() to decode.
func (*WrappedStream) Close ¶
func (s *WrappedStream) Close() error