Example #1
0
func (proxy *_Proxy) client(device *gorpc.Device) (*_Client, bool) {
	proxy.RLock()
	defer proxy.RUnlock()

	client, ok := proxy.clients[device.String()]

	return client, ok
}
Example #2
0
func newAgent(ctx gorpc.Context, handler *_TunnelClient, device *gorpc.Device) (*_Agent, error) {
	context := &_Agent{
		handler: handler,
		id:      device,
	}

	context.Sink = gorpc.NewSink(device.String(), context, ctx.Pipeline().TimeWheel(), handler.timeout)

	var err error

	err = handler.system.system.BindAgent(context)

	if err != nil {
		return nil, err
	}

	return context, nil
}
Example #3
0
func (handler *_TunnelClient) agent(context gorpc.Context, device *gorpc.Device) (*_Agent, error) {

	if agent, ok := handler.agents[device.String()]; ok {
		if agent.closed {
			agent.closed = false
			handler.system.system.BindAgent(agent)
		}
		return agent, nil
	}

	agent, err := newAgent(context, handler, device)

	if err != nil {
		return nil, err
	}

	handler.agents[device.String()] = agent

	return agent, nil
}