Browse Source

fix merge conflicts

pull/1095/head
Anton Kaliaev 7 years ago
parent
commit
747b73cb95
No known key found for this signature in database GPG Key ID: 7B6881D965918214
3 changed files with 20 additions and 15 deletions
  1. +16
    -11
      p2p/conn/connection.go
  2. +3
    -3
      p2p/conn/connection_test.go
  3. +1
    -1
      p2p/switch_test.go

+ 16
- 11
p2p/conn/connection.go View File

@ -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?


+ 3
- 3
p2p/conn/connection_test.go View File

@ -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)


+ 1
- 1
p2p/switch_test.go View File

@ -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},


Loading…
Cancel
Save