p2p

package
v0.0.0-...-a1d2bbf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtocolRequestID - protocol header id for request traffic
	ProtocolRequestID string = "/od/syncreq/1.0.0"

	// ProtocolResponseID - protocol header id for response traffic
	ProtocolResponseID string = "/od/syncresp/1.0.0"
)
View Source
const (
	MerkleHashRequest = "MerkleHashRequest"
)

Variables

View Source
var (
	ErrLNodeNotInitialized = errors.New("p2p: local node not initialized")
)

Functions

func ConnectToBootstrapNodes

func ConnectToBootstrapNodes(ln *LNode)

ConnectToBootstrapNodes initialize connection to hardcoded ipfs nodes addr.

func GetMerkleHash

func GetMerkleHash() error

func InitConn

func InitConn(port, nid string) error

InitConn main entry for initialization of p2p connections.

Types

type LNode

type LNode struct {
	host.Host
	RPC

	// Port for tcp connection of local node to listen to.
	Port string

	// NID (Network ID) is the rendez vous point for other nodes.
	NID string

	// Peers is the list of connected peers under the same NID.
	Peers []peer.ID
	// contains filtered or unexported fields
}

LNode represents a local node connection and is a wrapper around libp2p Host.

func NewLNode

func NewLNode(port, nid string) *LNode

func (*LNode) AddPeer

func (ln *LNode) AddPeer(pid peer.ID)

AddPeer adds a new peer id to the list of connected peer id.

func (*LNode) GetContext

func (ln *LNode) GetContext() context.Context

GetContext return current local node context.

func (*LNode) GetPeerID

func (ln *LNode) GetPeerID() peer.ID

GetPeerID returns the current local node peer id.

func (*LNode) Request

func (ln *LNode) Request(method string)

Request send a rpc call to connected peers.

type RPC

type RPC struct {

	// TODO: Might need to create a self contained context queue to timeout request pending for x amount of seconds.
	// ReqOut represents the queue outgoing requests from the current node.
	ReqOut map[string]*ReqResp

	// ReqIn represents a chan of incoming request to process.
	ReqIn chan *pb.Request
	// contains filtered or unexported fields
}

RPC handles the data stream from/to libp2p host and stores all incoming/outgoing request until fully resolve or timeout is reached.

func NewRpc

func NewRpc(lnode *LNode) *RPC

func (*RPC) RequestID

func (rpc *RPC) RequestID() protocol.ID

RequestID returns the procotol resquest id.

func (*RPC) RequestToPeer

func (rpc *RPC) RequestToPeer(peerID peer.ID, method string) (*pb.Response, error)

RequestToPeer opens a stream to a single peer and sends a proto request.

func (*RPC) ResponseID

func (rpc *RPC) ResponseID() protocol.ID

ResponseID returns the protol response id.

type ReqResp

type ReqResp struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL