diff --git a/ship/handshake.go b/ship/handshake.go index 1dc2c553..f552aba3 100644 --- a/ship/handshake.go +++ b/ship/handshake.go @@ -134,12 +134,7 @@ func (c *ShipConnection) handleState(timeout bool, message []byte) { c.handshakeHello_Init() case SmeHelloStateReadyListen: - if timeout { - c.handshakeHello_ReadyTimeout() - return - } - - c.handshakeHello_ReadyListen(message) + c.handshakeHello_ReadyListen(timeout, message) case SmeHelloStatePendingInit: c.handshakeHello_PendingInit() diff --git a/ship/hs_hello.go b/ship/hs_hello.go index 3c7c15a0..e460d35a 100644 --- a/ship/hs_hello.go +++ b/ship/hs_hello.go @@ -22,7 +22,12 @@ func (c *ShipConnection) handshakeHello_Init() { } // SME_HELLO_STATE_READY_LISTEN -func (c *ShipConnection) handshakeHello_ReadyListen(message []byte) { +func (c *ShipConnection) handshakeHello_ReadyListen(timeout bool, message []byte) { + if timeout { + c.handshakeHello_ReadyTimeout() + return + } + var helloReturnMsg model.ConnectionHello if err := c.processShipJsonMessage(message, &helloReturnMsg); err != nil { c.setState(SmeHelloStateAbort, nil) diff --git a/ship/hs_hello_test.go b/ship/hs_hello_test.go index 0babb1ee..db82e657 100644 --- a/ship/hs_hello_test.go +++ b/ship/hs_hello_test.go @@ -80,7 +80,7 @@ func (s *HelloSuite) Test_ReadyListen_Timeout() { time.Sleep(tHelloInit + time.Second) } else { // speed up the test by running the method directly - sut.handshakeHello_ReadyTimeout() + sut.handshakeHello_ReadyListen(true, nil) } assert.Equal(s.T(), SmeHelloStateAbortDone, sut.getState()) @@ -112,6 +112,32 @@ func (s *HelloSuite) Test_ReadyListen_Ignore() { shutdownTest(sut) } +func (s *HelloSuite) Test_ReadyListen_Prolongation() { + sut, data := initTest(s.role) + + sut.setState(SmeHelloStateReadyInit, nil) // inits the timer + sut.setState(SmeHelloStateReadyListen, nil) + + data.allowWaitingForTrust = true + + helloMsg := model.ConnectionHello{ + ConnectionHello: model.ConnectionHelloType{ + Phase: model.ConnectionHelloPhaseTypePending, + ProlongationRequest: util.Ptr(true), + }, + } + + msg, err := sut.shipMessage(model.MsgTypeControl, helloMsg) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), msg) + + sut.handleState(false, msg) + + assert.Equal(s.T(), SmeHelloStateReadyListen, sut.getState()) + + shutdownTest(sut) +} + func (s *HelloSuite) Test_ReadyListen_Abort() { sut, data := initTest(s.role)