Browse Source

minor cleanup

pull/1528/head
Ethan Buchman 6 years ago
parent
commit
0cbbb61962
5 changed files with 20 additions and 100 deletions
  1. +5
    -0
      CHANGELOG.md
  2. +0
    -79
      p2p/CHANGELOG.md
  3. +8
    -4
      p2p/peer.go
  4. +5
    -3
      p2p/switch.go
  5. +2
    -14
      p2p/switch_test.go

+ 5
- 0
CHANGELOG.md View File

@ -23,6 +23,11 @@ IMPROVEMENTS:
BUG FIXES:
- Graceful handling/recovery for apps that have non-determinism or fail to halt
- Graceful handling/recovery for violations of safety, or liveness
## 0.19.2 (TBD)
BUG FIXES:
- Fix reconnect to persistent peer when first dial fails
## 0.19.1 (April 27th, 2018)


+ 0
- 79
p2p/CHANGELOG.md View File

@ -1,79 +0,0 @@
# 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
- PeerConfig requires a Dial function
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

+ 8
- 4
p2p/peer.go View File

@ -90,8 +90,8 @@ type PeerConfig struct {
MConfig *tmconn.MConnConfig `mapstructure:"connection"`
Fail bool `mapstructure:"fail"` // for testing
Fuzz bool `mapstructure:"fuzz"` // fuzz connection (for testing)
DialFail bool `mapstructure:"dial_fail"` // for testing
Fuzz bool `mapstructure:"fuzz"` // fuzz connection (for testing)
FuzzConfig *FuzzConnConfig `mapstructure:"fuzz_config"`
}
@ -102,7 +102,7 @@ func DefaultPeerConfig() *PeerConfig {
HandshakeTimeout: 20, // * time.Second,
DialTimeout: 3, // * time.Second,
MConfig: tmconn.DefaultMConnConfig(),
Fail: false,
DialFail: false,
Fuzz: false,
FuzzConfig: DefaultFuzzConnConfig(),
}
@ -339,7 +339,11 @@ func (p *peer) String() string {
//------------------------------------------------------------------
// helper funcs
var dial = func(addr *NetAddress, config *PeerConfig) (net.Conn, error) {
func dial(addr *NetAddress, config *PeerConfig) (net.Conn, error) {
if config.DialFail {
return nil, fmt.Errorf("dial err (peerConfig.DialFail == true)")
}
conn, err := addr.DialTimeout(config.DialTimeout * time.Second)
if err != nil {
return nil, err


+ 5
- 3
p2p/switch.go View File

@ -283,11 +283,12 @@ func (sw *Switch) stopAndRemovePeer(peer Peer, reason interface{}) {
// with a fixed interval, then with exponential backoff.
// If no success after all that, it stops trying, and leaves it
// to the PEX/Addrbook to find the peer with the addr again
// NOTE: this will keep trying even if the handshake or auth fails.
// TODO: be more explicit with error types so we only retry on certain failures
func (sw *Switch) reconnectToPeer(addr *NetAddress) {
if sw.reconnecting.Has(string(addr.ID)) {
return
}
sw.reconnecting.Set(string(addr.ID), addr)
defer sw.reconnecting.Delete(string(addr.ID))
@ -381,13 +382,14 @@ func (sw *Switch) DialPeersAsync(addrBook AddrBook, peers []string, persistent b
go func(i int) {
j := perm[i]
addr := netAddrs[j]
// do not dial ourselves
if netAddrs[j].Same(ourAddr) {
if addr.Same(ourAddr) {
return
}
sw.randomSleep(0)
err := sw.DialPeerWithAddress(netAddrs[j], persistent)
err := sw.DialPeerWithAddress(addr, persistent)
if err != nil {
sw.Logger.Error("Error dialing peer", "err", err)
}


+ 2
- 14
p2p/switch_test.go View File

@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -23,20 +22,9 @@ var (
config *cfg.P2PConfig
)
var goodDial = dial
// badDial returns an error for testing dial errors
func badDial(addr *NetAddress, config *PeerConfig) (net.Conn, error) {
if config.Fail {
return nil, errors.New("dial err")
}
return goodDial(addr, config)
}
func init() {
config = cfg.DefaultP2PConfig()
config.PexReactor = true
dial = badDial
}
type PeerMessage struct {
@ -329,13 +317,13 @@ func TestSwitchReconnectsToPersistentPeer(t *testing.T) {
assert.False(peer.IsRunning())
// simulate another remote peer
rp = &remotePeer{PrivKey: crypto.GenPrivKeyEd25519().Wrap(), Config: DefaultPeerConfig()}
rp = &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: DefaultPeerConfig()}
rp.Start()
defer rp.Stop()
// simulate first time dial failure
peerConfig := DefaultPeerConfig()
peerConfig.Fail = true
peerConfig.DialFail = true
err = sw.addOutboundPeerWithConfig(rp.Addr(), peerConfig, true)
require.NotNil(err)


Loading…
Cancel
Save