Exemplo n.º 1
0
func (handler *_TunnelClient) Active(context gorpc.Context) error {

	handler.agents = make(map[string]*_Agent)

	handler.system.addTunnel(handler.name, handler, context.Pipeline())

	// send TunnelWhoAmI

	whoAmI := gorpc.NewTunnelWhoAmI()

	whoAmI.Services = handler.system.system.AgentServices()

	var buff bytes.Buffer

	gorpc.WriteTunnelWhoAmI(&buff, whoAmI)

	message := gorpc.NewMessage()

	message.Code = gorpc.CodeTunnelWhoAmI

	message.Content = buff.Bytes()

	context.Send(message)

	return nil
}
Exemplo n.º 2
0
func (handler *_HeartbeatHandler) timeoutLoop(context gorpc.Context, exitflag chan bool) {

	wheel := context.Pipeline().TimeWheel()

	ticker := wheel.NewTicker(handler.timeout)

	defer ticker.Stop()

	for {

		select {
		case <-ticker.C:

			if time.Now().Sub(handler.timestamp) > handler.timeout*2 {
				handler.context.Close()
				handler.W("heartbeat timeout(%s), close current pipeline(%s)", handler.timeout*2, handler.context.Pipeline())
				return
			}

			message := gorpc.NewMessage()

			message.Code = gorpc.CodeHeartbeat

			handler.context.Send(message)

			handler.V("%s send heartbeat message", handler.context.Pipeline())

		case <-exitflag:
			handler.V("exit heartbeat loop .....................")
			return
		}
	}
}
Exemplo n.º 3
0
Arquivo: dh.go Projeto: gsrpc/gorpc
func (handler *_CryptoClient) Active(context gorpc.Context) error {
	// create whoAmI message

	message := gorpc.NewMessage()

	message.Code = gorpc.CodeWhoAmI

	whoAmI := gorpc.NewWhoAmI()

	whoAmI.ID = handler.device

	whoAmI.Context = []byte(handler.dhKey.Exchange().String())

	var buff bytes.Buffer

	err := gorpc.WriteWhoAmI(&buff, whoAmI)

	if err != nil {
		context.Close()
		return err
	}

	message.Content = buff.Bytes()

	handler.V("send whoAmI handshake")

	context.Send(message)

	return gorpc.ErrSkip

}