Exemplo n.º 1
0
// handleCER handles Capabilities-Exchange-Request messages.
//
// If mandatory AVPs such as Origin-Host or Origin-Realm
// are missing, we close the connection.
//
// See RFC 6733 section 5.3 for details.
func handleCER(sm *StateMachine) diam.HandlerFunc {
	return func(c diam.Conn, m *diam.Message) {
		ctx := c.Context()
		if _, ok := smpeer.FromContext(ctx); ok {
			// Ignore retransmission.
			return
		}
		cer := new(smparser.CER)
		failedAVP, err := cer.Parse(m)
		if err != nil {
			if failedAVP != nil {
				err = errorCEA(sm, c, m, cer, failedAVP)
				if err != nil {
					sm.Error(&diam.ErrorReport{
						Conn:    c,
						Message: m,
						Error:   err,
					})
				}
			}
			c.Close()
			return
		}
		err = successCEA(sm, c, m, cer)
		if err != nil {
			sm.Error(&diam.ErrorReport{
				Conn:    c,
				Message: m,
				Error:   err,
			})
			return
		}
		meta := smpeer.FromCER(cer)
		c.SetContext(smpeer.NewContext(ctx, meta))
		// Notify about peer passing the handshake.
		select {
		case sm.hsNotifyc <- c:
		default:
		}
	}
}
Exemplo n.º 2
0
// handleCEA handles Capabilities-Exchange-Answer messages.
func handleCEA(sm *StateMachine, errc chan error) diam.HandlerFunc {
	return func(c diam.Conn, m *diam.Message) {
		cea := new(smparser.CEA)
		if err := cea.Parse(m); err != nil {
			errc <- err
			return
		}
		if cea.ResultCode != diam.Success {
			errc <- &ErrFailedResultCode{Code: cea.ResultCode}
			return
		}
		meta := smpeer.FromCEA(cea)
		c.SetContext(smpeer.NewContext(c.Context(), meta))
		// Notify about peer passing the handshake.
		select {
		case sm.hsNotifyc <- c:
		default:
		}
		// Done receiving and validating this CEA.
		close(errc)
	}
}