func (c MessageRouter) tryRoute(beginString *field.BeginStringField, msgType *field.MsgTypeField, msg Message, sessionID SessionID) MessageRejectError {

	if beginString.Value == fix.BeginString_FIXT11 && !fix.IsAdminMessageType(msgType.Value) {
		applVerID := &field.ApplVerIDField{}
		if err := msg.Header.Get(applVerID); err != nil {
			session, _ := LookupSession(sessionID)
			applVerID.Value = session.TargetDefaultApplicationVersionID()
		}

		switch applVerID.Value {
		case enum.ApplVerID_FIX40:
			beginString.Value = fix.BeginString_FIX40
		case enum.ApplVerID_FIX41:
			beginString.Value = fix.BeginString_FIX41
		case enum.ApplVerID_FIX42:
			beginString.Value = fix.BeginString_FIX42
		case enum.ApplVerID_FIX43:
			beginString.Value = fix.BeginString_FIX43
		case enum.ApplVerID_FIX44:
			beginString.Value = fix.BeginString_FIX44
		case enum.ApplVerID_FIX50, enum.ApplVerID_FIX50SP1, enum.ApplVerID_FIX50SP2:
			beginString.Value = fix.BeginString_FIX50
		}

		return c.tryRoute(beginString, msgType, msg, sessionID)
	}

	route, ok := c.routes[routeKey{beginString.Value, msgType.Value}]

	if !ok {
		return unsupportedMessageType()
	}

	return route(msg, sessionID)
}
Exemple #2
0
func (s *Session) fromCallback(msg Message) MessageRejectError {
	msgType := new(fix.StringValue)
	if msg.Header.GetField(tag.MsgType, msgType); fix.IsAdminMessageType(msgType.Value) {
		return s.application.FromAdmin(msg, s.sessionID)
	}

	return s.application.FromApp(msg, s.sessionID)
}
Exemple #3
0
func (s *Session) verifySelect(msg Message, checkTooHigh bool, checkTooLow bool) MessageRejectError {
	if reject := s.checkBeginString(msg); reject != nil {
		return reject
	}

	if reject := s.checkCompID(msg); reject != nil {
		return reject
	}

	if reject := s.checkSendingTime(msg); reject != nil {
		return reject
	}

	if checkTooLow {
		if reject := s.checkTargetTooLow(msg); reject != nil {
			return reject
		}
	}

	if checkTooHigh {
		if reject := s.checkTargetTooHigh(msg); reject != nil {
			return reject
		}
	}

	if s.dataDictionary != nil {
		if reject := validate(s.dataDictionary, msg); reject != nil {
			return reject
		}
	}

	if s.transportDataDictionary != nil {
		var msgType field.MsgTypeField
		msg.Header.Get(&msgType)
		if fix.IsAdminMessageType(msgType.Value) {
			if reject := validate(s.transportDataDictionary, msg); reject != nil {
				return reject
			}
		} else {
			if reject := validateFIXTApp(s.transportDataDictionary, s.appDataDictionary, msg); reject != nil {
				return reject
			}
		}
	}

	return s.fromCallback(msg)
}
Exemple #4
0
func (s *Session) send(builder MessageBuilder) {
	s.fillDefaultHeader(builder)

	seqNum := s.store.NextSenderMsgSeqNum()
	builder.Header().Set(fix.NewIntField(tag.MsgSeqNum, seqNum))

	msgType := new(fix.StringValue)
	if builder.Header().GetField(tag.MsgType, msgType); fix.IsAdminMessageType(msgType.Value) {
		s.application.ToAdmin(builder, s.sessionID)
	} else {
		s.application.ToApp(builder, s.sessionID)
	}
	if msgBytes, err := builder.Build(); err != nil {
		panic(err)
	} else {
		s.store.SaveMessage(seqNum, msgBytes)
		s.sendBytes(msgBytes)
		s.store.IncrNextSenderMsgSeqNum()
	}
}
func (state inSession) resendMessages(session *Session, beginSeqNo, endSeqNo int) {
	msgs := session.store.GetMessages(beginSeqNo, endSeqNo)

	seqNum := beginSeqNo
	nextSeqNum := seqNum

	var msgBytes []byte
	var ok bool
	for {
		if msgBytes, ok = <-msgs; !ok {
			//gapfill for catch-up
			if seqNum != nextSeqNum {
				state.generateSequenceReset(session, seqNum, nextSeqNum)
			}

			return
		}

		msg, _ := parseMessage(msgBytes)

		msgType := new(fix.StringValue)
		msg.Header.GetField(tag.MsgType, msgType)

		sentMessageSeqNum := new(fix.IntValue)
		msg.Header.GetField(tag.MsgSeqNum, sentMessageSeqNum)

		if fix.IsAdminMessageType(msgType.Value) {
			nextSeqNum = sentMessageSeqNum.Value + 1
		} else {

			if seqNum != sentMessageSeqNum.Value {
				state.generateSequenceReset(session, seqNum, sentMessageSeqNum.Value)
			}

			session.resend(msg)
			seqNum = sentMessageSeqNum.Value + 1
			nextSeqNum = seqNum
		}
	}
}