You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Ethan Buchman 63f546497b Merge remote-tracking branch 'p2p/develop' into repo-merge 8 years ago
.github add ISSUE_TEMPLATE for github [ci skip] [circle skip] 8 years ago
DOCKER rename TMROOT to TMHOME (Refs #431) 8 years ago
benchmarks Lots of updates to use new go-crypto / json style 8 years ago
blockchain Merge pull request #450 from tendermint/fix-fastsync 8 years ago
cmd/tendermint Lots of updates to use new go-crypto / json style 8 years ago
config Lots of updates to use new go-crypto / json style 8 years ago
consensus Ensure private validator addresses are hex 8 years ago
docs/architecture some docs fixes 8 years ago
mempool log warning if peer send failed (Refs #174) 8 years ago
node Lots of updates to use new go-crypto / json style 8 years ago
premerge premerge 8 years ago
proxy remove BaseService.OnStart 8 years ago
rpc move into rpc package 8 years ago
scripts Revert "Undo last two commits" 8 years ago
state post rebase fixes 8 years ago
upnp use tmlibs 8 years ago
version version bump 8 years ago
.codecov.yml test: remove codecov patch threshold 8 years ago
.editorconfig add .editorconfig to maintain consistent coding style 8 years ago
.gitignore collect and add docker logs to CircleCI artifacts (Refs #387) 8 years ago
CHANGELOG.md update changelog 8 years ago
Dockerfile add Dockerfile 8 years ago
LICENSE Change license to Apache2.0 9 years ago
README.md circle badge 9 years ago
addrbook.go use tmlibs 8 years ago
addrbook_test.go fix merge 8 years ago
config.go test peer 8 years ago
connection.go use tmlibs 8 years ago
connection_test.go it is non-deterministic (could fail sometimes) 8 years ago
fuzz.go [fuzz] only one way to set config variables 8 years ago
glide.lock use tmlibs 8 years ago
glide.yaml use tmlibs 8 years ago
ip_range_counter.go Add RemoteAddr and ListenAddr to NodeInfo; Refactor IPRange logic 9 years ago
listener.go use tmlibs 8 years ago
listener_test.go MakeConnectedSwitches function 9 years ago
log.go use tmlibs 8 years ago
netaddress.go use tmlibs 8 years ago
netaddress_test.go tests for NetAddress 8 years ago
peer.go crypto Wrap/Unwrap 8 years ago
peer_set.go Add RemoteAddr and ListenAddr to NodeInfo; Refactor IPRange logic 9 years ago
peer_set_test.go use tmlibs 8 years ago
peer_test.go crypto Wrap/Unwrap 8 years ago
pex_reactor.go use tmlibs 8 years ago
pex_reactor_test.go use tmlibs 8 years ago
secret_connection.go crypto Wrap/Unwrap 8 years ago
secret_connection_test.go crypto Wrap/Unwrap 8 years ago
switch.go crypto Wrap/Unwrap 8 years ago
switch_test.go use tmlibs 8 years ago
types.go close conns on filter; fix order in MakeConnectedSwitch 8 years ago
util.go initial commit 9 years ago
version.go CHANGELOG and version bump 8 years ago

README.md

tendermint/go-p2p

CircleCI

tendermint/go-p2p provides an abstraction around peer-to-peer communication.

Peer/MConnection/Channel

Each peer has one MConnection (multiplex connection) instance.

multiplex noun a system or signal involving simultaneous transmission of several messages along a single channel of communication.

Each MConnection handles message transmission on multiple abstract communication Channels. Each channel has a globally unique byte id. The byte id and the relative priorities of each Channel are configured upon initialization of the connection.

There are two methods for sending messages:

func (m MConnection) Send(chID byte, msg interface{}) bool {}
func (m MConnection) TrySend(chID byte, msg interface{}) bool {}

Send(chID, msg) is a blocking call that waits until msg is successfully queued for the channel with the given id byte chID. The message msg is serialized using the tendermint/wire submodule's WriteBinary() reflection routine.

TrySend(chID, msg) is a nonblocking call that returns false if the channel's queue is full.

Send() and TrySend() are also exposed for each Peer.

Switch/Reactor

The Switch handles peer connections and exposes an API to receive incoming messages on Reactors. Each Reactor is responsible for handling incoming messages of one or more Channels. So while sending outgoing messages is typically performed on the peer, incoming messages are received on the reactor.

// Declare a MyReactor reactor that handles messages on MyChannelID.
type MyReactor struct{}

func (reactor MyReactor) GetChannels() []*ChannelDescriptor {
    return []*ChannelDescriptor{ChannelDescriptor{ID:MyChannelID, Priority: 1}}
}

func (reactor MyReactor) Receive(chID byte, peer *Peer, msgBytes []byte) {
    r, n, err := bytes.NewBuffer(msgBytes), new(int64), new(error)
    msgString := ReadString(r, n, err)
    fmt.Println(msgString)
}

// Other Reactor methods omitted for brevity
...

switch := NewSwitch([]Reactor{MyReactor{}})

...

// Send a random message to all outbound connections
for _, peer := range switch.Peers().List() {
    if peer.IsOutbound() {
        peer.Send(MyChannelID, "Here's a random message")
    }
}

PexReactor/AddrBook

A PEXReactor reactor implementation is provided to automate peer discovery.

book := p2p.NewAddrBook(addrBookFilePath)
pexReactor := p2p.NewPEXReactor(book)
...
switch := NewSwitch([]Reactor{pexReactor, myReactor, ...})