Example #1
0
func (state inSession) Timeout(session *Session, event event) (nextState sessionState) {
	switch event {
	case needHeartbeat:
		heartBt := NewMessageBuilder()
		heartBt.Header().Set(field.NewMsgType("0"))
		session.send(heartBt)
	case peerTimeout:
		testReq := NewMessageBuilder()
		testReq.Header().Set(field.NewMsgType("1"))
		testReq.Body().Set(field.NewTestReqID("TEST"))
		session.send(testReq)
		session.peerTimer.Reset(time.Duration(int64(1.2 * float64(session.heartBeatTimeout))))
		return pendingTimeout{}
	}
	return state
}
Example #2
0
func (state inSession) handleTestRequest(session *Session, msg Message) (nextState sessionState) {
	if err := session.verify(msg); err != nil {
		return state.processReject(session, msg, err)
	}

	var testReq field.TestReqIDField
	if err := msg.Body.Get(&testReq); err != nil {
		session.log.OnEvent("Test Request with no testRequestID")
	} else {
		heartBt := NewMessageBuilder()
		heartBt.Header().Set(field.NewMsgType("0"))
		heartBt.Body().Set(field.NewTestReqID(testReq.Value))
		session.send(heartBt)
	}

	session.store.IncrNextTargetMsgSeqNum()

	return state
}