+++ /dev/null
-# Changelog
-
-## 0.5.0 (April 21, 2017)
-
-BREAKING CHANGES:
-
-- Remove or unexport methods from FuzzedConnection: Active, Mode, ProbDropRW, ProbDropConn, ProbSleep, MaxDelayMilliseconds, Fuzz
-- switch.AddPeerWithConnection is unexported and replaced by switch.AddPeer
-- switch.DialPeerWithAddress takes a bool, setting the peer as persistent or not
-
-FEATURES:
-
-- Persistent peers: any peer considered a "seed" will be reconnected to when the connection is dropped
-
-
-IMPROVEMENTS:
-
-- Many more tests and comments
-- Refactor configurations for less dependence on go-config. Introduces new structs PeerConfig, MConnConfig, FuzzConnConfig
-- New methods on peer: CloseConn, HandshakeTimeout, IsPersistent, Addr, PubKey
-- NewNetAddress supports a testing mode where the address defaults to 0.0.0.0:0
-
-
-## 0.4.0 (March 6, 2017)
-
-BREAKING CHANGES:
-
-- DialSeeds now takes an AddrBook and returns an error: `DialSeeds(*AddrBook, []string) error`
-- NewNetAddressString now returns an error: `NewNetAddressString(string) (*NetAddress, error)`
-
-FEATURES:
-
-- `NewNetAddressStrings([]string) ([]*NetAddress, error)`
-- `AddrBook.Save()`
-
-IMPROVEMENTS:
-
-- PexReactor responsible for starting and stopping the AddrBook
-
-BUG FIXES:
-
-- DialSeeds returns an error instead of panicking on bad addresses
-
-## 0.3.5 (January 12, 2017)
-
-FEATURES
-
-- Toggle strict routability in the AddrBook
-
-BUG FIXES
-
-- Close filtered out connections
-- Fixes for MakeConnectedSwitches and Connect2Switches
-
-## 0.3.4 (August 10, 2016)
-
-FEATURES:
-
-- Optionally filter connections by address or public key
-
-## 0.3.3 (May 12, 2016)
-
-FEATURES:
-
-- FuzzConn
-
-## 0.3.2 (March 12, 2016)
-
-IMPROVEMENTS:
-
-- Memory optimizations
-
-## 0.3.1 ()
-
-FEATURES:
-
-- Configurable parameters
-
+++ /dev/null
-FROM golang:latest
-
-RUN curl https://glide.sh/get | sh
-
-RUN mkdir -p /go/src/github.com/tendermint/tendermint/p2p
-WORKDIR /go/src/github.com/tendermint/tendermint/p2p
-
-COPY glide.yaml /go/src/github.com/tendermint/tendermint/p2p/
-COPY glide.lock /go/src/github.com/tendermint/tendermint/p2p/
-
-RUN glide install
-
-COPY . /go/src/github.com/tendermint/tendermint/p2p
+++ /dev/null
-# `tendermint/tendermint/p2p`
-
-[![CircleCI](https://circleci.com/gh/tendermint/tendermint/p2p.svg?style=svg)](https://circleci.com/gh/tendermint/tendermint/p2p)
-
-`tendermint/tendermint/p2p` provides an abstraction around peer-to-peer communication.<br/>
-
-## 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
-`Channel`s. 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:
-```go
-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.
-
-```go
-// 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.
-
-```go
-book := p2p.NewAddrBook(addrBookFilePath)
-pexReactor := p2p.NewPEXReactor(book)
-...
-switch := NewSwitch([]Reactor{pexReactor, myReactor, ...})
-```
// max addresses returned by GetSelection
// NOTE: this must match "maxPexMessageSize"
maxGetSelection = 250
-
- // current version of the on-disk format.
- serializationVersion = 1
)
const (
type AddrBook struct {
cmn.BaseService
- mtx sync.Mutex
+ // immutable after creation
filePath string
routabilityStrict bool
- rand *rand.Rand
key string
- ourAddrs map[string]*NetAddress
- addrLookup map[string]*knownAddress // new & old
- addrNew []map[string]*knownAddress
- addrOld []map[string]*knownAddress
- wg sync.WaitGroup
- nOld int
- nNew int
+
+ mtx sync.Mutex
+ rand *rand.Rand
+ ourAddrs map[string]*NetAddress
+ addrLookup map[string]*knownAddress // new & old
+ addrNew []map[string]*knownAddress
+ addrOld []map[string]*knownAddress
+ nOld int
+ nNew int
+
+ wg sync.WaitGroup
}
// NewAddrBook creates a new address book.
+++ /dev/null
-package p2p
-
-import (
- "strings"
-)
-
-// TODO Test
-func AddToIPRangeCounts(counts map[string]int, ip string) map[string]int {
- changes := make(map[string]int)
- ipParts := strings.Split(ip, ":")
- for i := 1; i < len(ipParts); i++ {
- prefix := strings.Join(ipParts[:i], ":")
- counts[prefix] += 1
- changes[prefix] = counts[prefix]
- }
- return changes
-}
-
-// TODO Test
-func CheckIPRangeCounts(counts map[string]int, limits []int) bool {
- for prefix, count := range counts {
- ipParts := strings.Split(prefix, ":")
- numParts := len(ipParts)
- if limits[numParts] < count {
- return false
- }
- }
- return true
-}