interface.go 1.38 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3 4 5
package net

import (
	msg "github.com/jbenet/go-ipfs/net/message"
	mux "github.com/jbenet/go-ipfs/net/mux"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
6
	srv "github.com/jbenet/go-ipfs/net/service"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
7 8 9 10 11 12 13 14 15 16 17
	peer "github.com/jbenet/go-ipfs/peer"
)

// Network is the interface IPFS uses for connecting to the world.
type Network interface {

	// Listen handles incoming connections on given Multiaddr.
	// Listen(*ma.Muliaddr) error
	// TODO: for now, only listen on addrs in local peer when initializing.

	// DialPeer attempts to establish a connection to a given peer
18
	DialPeer(peer.Peer) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
19 20

	// ClosePeer connection to peer
21
	ClosePeer(peer.Peer) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
22 23

	// IsConnected returns whether a connection to given peer exists.
24
	IsConnected(peer.Peer) (bool, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
25 26 27 28

	// GetProtocols returns the protocols registered in the network.
	GetProtocols() *mux.ProtocolMap

29
	// GetPeerList returns the list of peers currently connected in this network.
30
	GetPeerList() []peer.Peer
31

32 33 34 35
	// GetBandwidthTotals returns the total number of bytes passed through
	// the network since it was instantiated
	GetBandwidthTotals() (uint64, uint64)

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
36
	// SendMessage sends given Message out
37
	SendMessage(msg.NetMessage) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
38 39 40 41

	// Close terminates all network operation
	Close() error
}
42 43

// Sender interface for network services.
44
type Sender srv.Sender
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
45 46 47

// Handler interface for network services.
type Handler srv.Handler
48 49 50

// Service interface for network resources.
type Service srv.Service