p2p

package
v0.0.0-...-4496321 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_PROTO = "tcp"
	NETWORK       = "SPACEMINT"
	PART_SIZE     = 1024 * 16
	SKIP_UPNP     = false
	VERSION       = "0.0.0"
)
View Source
const (
	// Channels
	DATA_CHANNEL byte = 0x20

	PEER_STATE_KEY           = "peer_state"
	MAX_MESSAGE_SIZE         = 1024 * 100 // 100KB
	BROADCAST_SLEEP_DURATION = 2 * time.Second
	GOSSIP_SLEEP_DURATION    = 100 * time.Millisecond
)
View Source
const (
	// PEX
	PARTS_HEADER byte = 0x01
	HAS_PARTS    byte = 0x02
	HAS_PART     byte = 0x03
	PART         byte = 0x04
	SHUTDOWN     byte = 0x05
)

Messages

Variables

View Source
var (
	ErrPartSetUnexpectedIndex = Error("Error part set unexpected index")
	ErrPartSetInvalidProof    = Error("Error part set invalid roof")
)

Functions

func NewConfig

func NewConfig(bookPath, configPath, input, laddr, output string, priv crypto.PrivKeyEd25519, seeds string, seedsLimit int) cfg.Config

func ProtocolAndAddress

func ProtocolAndAddress(laddr string) (string, string)

func ReadConfig

func ReadConfig(configPath string) cfg.Config

Types

type BitArray

type BitArray []byte

func NewBitArray

func NewBitArray(size int) BitArray

func (BitArray) Has

func (bits BitArray) Has(idx int) bool

func (BitArray) Len

func (bits BitArray) Len() int

func (BitArray) Set

func (bits BitArray) Set(idx int) bool

func (BitArray) Size

func (bits BitArray) Size() int

type DataMessage

type DataMessage interface{}

func DecodeMessage

func DecodeMessage(bz []byte) (byte, DataMessage, error)

type DataReactor

type DataReactor struct {
	gop2p.BaseReactor
	// contains filtered or unexported fields
}

func NewDataReactor

func NewDataReactor() *DataReactor

func (*DataReactor) AddPeer

func (reactor *DataReactor) AddPeer(peer *gop2p.Peer)

func (*DataReactor) GetChannels

func (reactor *DataReactor) GetChannels() []*gop2p.ChannelDescriptor

func (*DataReactor) GetOutputPath

func (reactor *DataReactor) GetOutputPath() string

func (*DataReactor) GetParts

func (reactor *DataReactor) GetParts() *PartSet

func (*DataReactor) GetPartsHeader

func (reactor *DataReactor) GetPartsHeader() PartSetHeader

func (*DataReactor) OnStart

func (reactor *DataReactor) OnStart() error

func (*DataReactor) OnStop

func (reactor *DataReactor) OnStop()

func (*DataReactor) Receive

func (reactor *DataReactor) Receive(chID byte, src *gop2p.Peer, msgBytes []byte)

func (*DataReactor) RemovePeer

func (reactor *DataReactor) RemovePeer(peer *gop2p.Peer, reason interface{})

func (*DataReactor) SetOutputPath

func (reactor *DataReactor) SetOutputPath(path string)

func (*DataReactor) SetParts

func (reactor *DataReactor) SetParts(parts *PartSet) bool

func (*DataReactor) SetPartsHeader

func (reactor *DataReactor) SetPartsHeader(header PartSetHeader) bool

type HasPartMessage

type HasPartMessage struct {
	Idx int
}

type HasPartsMessage

type HasPartsMessage struct {
	HasParts BitArray
}

type Node

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

func NewNode

func NewNode(config cfg.Config) *Node

func RunNode

func RunNode(configPath string) *Node

func (*Node) AddListener

func (nd *Node) AddListener(lis gop2p.Listener)

func (*Node) DataReactor

func (nd *Node) DataReactor() *DataReactor

func (*Node) DialSeeds

func (nd *Node) DialSeeds(seeds []string)

func (*Node) NodeInfo

func (nd *Node) NodeInfo() *gop2p.NodeInfo

func (*Node) PexReactor

func (nd *Node) PexReactor() *gop2p.PEXReactor

func (*Node) ShutdownPeers

func (nd *Node) ShutdownPeers()

func (*Node) Start

func (nd *Node) Start() error

func (*Node) Stop

func (nd *Node) Stop()

func (*Node) Switch

func (nd *Node) Switch() *gop2p.Switch

type Part

type Part struct {
	Bytes []byte

	Idx   int
	Proof *merkle.MemProof
	// contains filtered or unexported fields
}

func (*Part) Hash

func (part *Part) Hash() []byte

type PartMessage

type PartMessage struct {
	Part *Part
}

type PartSet

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

func NewPartSetFromData

func NewPartSetFromData(data []byte, partSize int) *PartSet

func NewPartSetFromHeader

func NewPartSetFromHeader(header PartSetHeader) *PartSet

func (*PartSet) AddPart

func (partSet *PartSet) AddPart(p *Part) (bool, error)

func (*PartSet) Bits

func (partSet *PartSet) Bits() BitArray

func (*PartSet) Count

func (partSet *PartSet) Count() int

func (*PartSet) GetPart

func (partSet *PartSet) GetPart(idx int) *Part

func (*PartSet) GetReader

func (partSet *PartSet) GetReader() io.Reader

func (*PartSet) HasHeader

func (partSet *PartSet) HasHeader(header PartSetHeader) bool

func (*PartSet) Hash

func (partSet *PartSet) Hash() []byte

func (*PartSet) HashesTo

func (partSet *PartSet) HashesTo(hash []byte) bool

func (*PartSet) Header

func (partSet *PartSet) Header() (header PartSetHeader)

func (*PartSet) IsComplete

func (partSet *PartSet) IsComplete() bool

type PartSetHeader

type PartSetHeader struct {
	Hash  []byte
	Total int
}

func (PartSetHeader) Equals

func (header PartSetHeader) Equals(other PartSetHeader) bool

func (PartSetHeader) IsZero

func (header PartSetHeader) IsZero() bool

type PartSetReader

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

func NewPartSetReader

func NewPartSetReader(parts []*Part) *PartSetReader

func (*PartSetReader) Read

func (r *PartSetReader) Read(p []byte) (int, error)

Iterative read

type PartsHeaderMessage

type PartsHeaderMessage struct {
	Header PartSetHeader
}

type PeerState

type PeerState struct {
	Peer *gop2p.Peer
	// contains filtered or unexported fields
}

Peer State

func NewPeerState

func NewPeerState(peer *gop2p.Peer) *PeerState

func (*PeerState) Disconnect

func (peerState *PeerState) Disconnect() bool

func (*PeerState) GetHasParts

func (peerState *PeerState) GetHasParts() BitArray

func (*PeerState) SentMessage

func (peerState *PeerState) SentMessage(msg DataMessage)

func (*PeerState) SetHasPart

func (peerState *PeerState) SetHasPart(idx int) bool

type ShutdownMessage

type ShutdownMessage struct{}

Jump to

Keyboard shortcuts

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