From 747b73cb95dab52ee1076ce83dcc92dca86ef93a Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 23 Jan 2018 13:11:44 +0400 Subject: [PATCH] fix merge conflicts --- p2p/conn/connection.go | 27 ++++++++++++++++----------- p2p/conn/connection_test.go | 6 +++--- p2p/switch_test.go | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index 25aac3012..71d8608fb 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -97,12 +97,17 @@ type MConnConfig struct { SendRate int64 `mapstructure:"send_rate"` RecvRate int64 `mapstructure:"recv_rate"` - MaxMsgPacketPayloadSize int + // Maximum payload size + MaxMsgPacketPayloadSize int `mapstructure:"max_msg_packet_payload_size"` - FlushThrottle time.Duration + // Interval to flush writes (throttled) + FlushThrottle time.Duration `mapstructure:"flush_throttle"` - pingInterval time.Duration - pongTimeout time.Duration + // Interval to send pings + PingInterval time.Duration `mapstructure:"ping_interval"` + + // Maximum wait time for pongs + PongTimeout time.Duration `mapstructure:"pong_timeout"` } func (cfg *MConnConfig) maxMsgPacketTotalSize() int { @@ -116,8 +121,8 @@ func DefaultMConnConfig() *MConnConfig { RecvRate: defaultRecvRate, MaxMsgPacketPayloadSize: defaultMaxMsgPacketPayloadSize, FlushThrottle: defaultFlushThrottle, - pingInterval: defaultPingInterval, - pongTimeout: defaultPongTimeout, + PingInterval: defaultPingInterval, + PongTimeout: defaultPongTimeout, } } @@ -133,7 +138,7 @@ func NewMConnection(conn net.Conn, chDescs []*ChannelDescriptor, onReceive recei // NewMConnectionWithConfig wraps net.Conn and creates multiplex connection with a config func NewMConnectionWithConfig(conn net.Conn, chDescs []*ChannelDescriptor, onReceive receiveCbFunc, onError errorCbFunc, config *MConnConfig) *MConnection { - if config.pongTimeout >= config.pingInterval { + if config.PongTimeout >= config.PingInterval { panic("pongTimeout must be less than pingInterval (otherwise, next ping will reset pong timer)") } @@ -180,9 +185,9 @@ func (c *MConnection) OnStart() error { return err } c.quit = make(chan struct{}) - c.flushTimer = cmn.NewThrottleTimer("flush", c.config.flushThrottle) - c.pingTimer = cmn.NewRepeatTimer("ping", c.config.pingInterval) - c.pongTimer = time.NewTimer(c.config.pongTimeout) + c.flushTimer = cmn.NewThrottleTimer("flush", c.config.FlushThrottle) + c.pingTimer = cmn.NewRepeatTimer("ping", c.config.PingInterval) + c.pongTimer = time.NewTimer(c.config.PongTimeout) // we start timer once we've send ping; needed here because we use start // listening in recvRoutine _ = c.pongTimer.Stop() @@ -334,7 +339,7 @@ FOR_LOOP: c.sendMonitor.Update(int(n)) c.flush() c.Logger.Debug("Starting pong timer") - c.pongTimer.Reset(c.config.pongTimeout) + c.pongTimer.Reset(c.config.PongTimeout) case <-c.pongTimer.C: c.Logger.Debug("Pong timeout") // XXX: should we decrease peer score instead of closing connection? diff --git a/p2p/conn/connection_test.go b/p2p/conn/connection_test.go index 4fb8d3412..d505805ed 100644 --- a/p2p/conn/connection_test.go +++ b/p2p/conn/connection_test.go @@ -24,8 +24,8 @@ func createTestMConnection(conn net.Conn) *MConnection { func createMConnectionWithCallbacks(conn net.Conn, onReceive func(chID byte, msgBytes []byte), onError func(r interface{})) *MConnection { chDescs := []*ChannelDescriptor{&ChannelDescriptor{ID: 0x01, Priority: 1, SendQueueCapacity: 1}} cfg := DefaultMConnConfig() - cfg.pingInterval = 60 * time.Millisecond - cfg.pongTimeout = 45 * time.Millisecond + cfg.PingInterval = 60 * time.Millisecond + cfg.PongTimeout = 45 * time.Millisecond c := NewMConnectionWithConfig(conn, chDescs, onReceive, onError, cfg) c.SetLogger(log.TestingLogger()) return c @@ -142,7 +142,7 @@ func TestMConnectionPongTimeoutResultsInError(t *testing.T) { server.Read(make([]byte, 1)) }() - expectErrorAfter := (mconn.config.pingInterval + mconn.config.pongTimeout) * 2 + expectErrorAfter := (mconn.config.PingInterval + mconn.config.PongTimeout) * 2 select { case msgBytes := <-receivedCh: t.Fatalf("Expected error, but got %v", msgBytes) diff --git a/p2p/switch_test.go b/p2p/switch_test.go index be1d96e9b..745eb44e6 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -301,7 +301,7 @@ func TestSwitchFullConnectivity(t *testing.T) { } func BenchmarkSwitchBroadcast(b *testing.B) { - s1, s2 := makeSwitchPair(b, func(i int, sw *Switch) *Switch { + s1, s2 := MakeSwitchPair(b, func(i int, sw *Switch) *Switch { // Make bar reactors of bar channels each sw.AddReactor("foo", NewTestReactor([]*conn.ChannelDescriptor{ {ID: byte(0x00), Priority: 10},