interface.go 1.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
package network

import (
	"context"

	gsmsg "github.com/ipfs/go-graphsync/message"

	peer "github.com/libp2p/go-libp2p-peer"
	protocol "github.com/libp2p/go-libp2p-protocol"
)

var (
	// ProtocolGraphsync is the protocol identifier for graphsync messages
	ProtocolGraphsync protocol.ID = "/ipfs/graphsync/1.0.0"
)

// GraphSyncNetwork provides network connectivity for GraphSync.
type GraphSyncNetwork interface {

	// SendMessage sends a GraphSync message to a peer.
	SendMessage(
		context.Context,
		peer.ID,
		gsmsg.GraphSyncMessage) error

	// SetDelegate registers the Reciver to handle messages received from the
	// network.
	SetDelegate(Receiver)

30 31 32
	// ConnectTo establishes a connection to the given peer
	ConnectTo(context.Context, peer.ID) error

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	NewMessageSender(context.Context, peer.ID) (MessageSender, error)
}

// MessageSender is an interface to send messages to a peer
type MessageSender interface {
	SendMsg(context.Context, gsmsg.GraphSyncMessage) error
	Close() error
	Reset() error
}

// Receiver is an interface for receiving messages from the GraphSyncNetwork.
type Receiver interface {
	ReceiveMessage(
		ctx context.Context,
		sender peer.ID,
		incoming gsmsg.GraphSyncMessage)

	ReceiveError(error)
}