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.
 
 
 
 
 
 
Anton Kaliaev c9cd8de9c6
set logger
7 years ago
..
upnp [p2p] refactor upnp to use new logger 7 years ago
CHANGELOG.md move into p2p package 7 years ago
Dockerfile go-p2p -> tendermint/p2p 7 years ago
README.md go-p2p -> tendermint/p2p 7 years ago
addrbook.go new logging 7 years ago
addrbook_test.go new logging 7 years ago
connection.go new logging 7 years ago
connection_test.go new logging 7 years ago
fuzz.go move into p2p package 7 years ago
glide.lock new logging 7 years ago
ip_range_counter.go move into p2p package 7 years ago
listener.go new logging 7 years ago
listener_test.go new logging 7 years ago
netaddress.go move into p2p package 7 years ago
netaddress_test.go One silly tests passes on osx, fails on linux... comment out so i can develop 7 years ago
peer.go new logging 7 years ago
peer_set.go p2p: fix race by peer.Start() before peers.Add() 7 years ago
peer_set_test.go p2p: use cmn instead of . 7 years ago
peer_test.go move into p2p package 7 years ago
pex_reactor.go new logging 7 years ago
pex_reactor_test.go set logger 7 years ago
secret_connection.go p2p: use cmn instead of . 7 years ago
secret_connection_test.go p2p: use cmn instead of . 7 years ago
switch.go set logger 7 years ago
switch_test.go p2p: fix race by peer.Start() before peers.Add() 7 years ago
types.go move into p2p package 7 years ago
util.go move into p2p package 7 years ago
version.go move into p2p package 7 years ago

README.md

tendermint/tendermint/p2p

CircleCI

tendermint/tendermint/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, ...})