Example #1
0
// Reads and responds to a HELO handshake from the service. If the handshake
// succeeds, the connection will transition to the `readServiceRequest` state.
func readServiceHelo(c *serviceConn) (serviceState, error) {
	helo := &ServiceHelo{
		MaxBatch: cap(c.recycleChan),
	}
	if _, err := helo.ReadServiceRequest(c.readWriter); err != nil {
		return nil, err
	}
	maxVersion, ok := c.Router.Config().Service.SatisfiesVersion(helo.Version)
	if !ok {
		helo.Version = maxVersion
	}
	if _, err := helo.WriteServiceReply(c.readWriter); err != nil {
		return nil, err
	}
	if err := c.readWriter.Flush(); err != nil {
		return nil, err
	}
	if !ok {
		return nil, nil
	}
	for index := 0; index < cap(c.recycleChan); index++ {
		c.recycleChan <- &DeliverRequest{
			ConnId:      c.id,
			RecycleChan: c.recycleChan,
		}
	}
	if err := c.Router.AddServiceConn(c, common.ToServiceName(helo.ServiceName)); err != nil {
		return nil, err
	}
	return readServiceRequest, nil
}
Example #2
0
// Reads and responds to a HELO handshake from the service socket. If the
// handshake is successful, the connection will be added to the router
// and transition to the `readServiceReply` state.
func readServiceHelo(conn *serviceConn) (next serviceState, err error) {
	config := conn.Router.Config().Service
	// TODO: Consider maintaining a `sync.Pool` of `NodeHelo` and
	// `ServiceHelo` structs (`helo.Zero(); pool.Put(helo)`). These
	// reconnections should not occur frequently, though.
	helo := &ServiceHelo{
		MaxBatch: config.MaxBatch,
	}
	if _, err = helo.ReadServiceRequest(conn.readWriter); err != nil {
		return nil, err
	}
	maxVersion, ok := config.SupportsVersion(helo.Version)
	if !ok {
		helo.Version = maxVersion
	}
	if _, err = helo.WriteServiceReply(conn.readWriter); err != nil {
		return nil, err
	}
	if err = conn.readWriter.Flush(); err != nil {
		return nil, err
	}
	if !ok {
		return nil, nil
	}
	conn.service = common.ToServiceName(helo.ServiceName)
	if err = conn.Router.AddServiceConn(conn, conn.service); err != nil {
		return nil, err
	}
	return readServiceReply, nil
}
Example #3
0
func (request *DeviceChangeRequest) Service() string {
	return common.ToServiceName(request.ServiceName)
}
Example #4
0
func (request *DeliverRequest) Service() string {
	return common.ToServiceName(request.ServiceName)
}