Exemplo n.º 1
0
func (c *DialerChain) Dial(network, host string) (conn net.Conn, err error) {
	var dialer transport.Dialer
	if dialer, err = c.Build(); err == nil {
		return dialer.Dial(network, host)
	}
	return
}
Exemplo n.º 2
0
func (c *DialerChain) DialWithMeasurements(network, host string) (fields common.MapStr, conn net.Conn, err error) {
	var dialer transport.Dialer
	fields = common.MapStr{}
	if dialer, err = c.BuildWithMeasures(fields); err == nil {
		conn, err = dialer.Dial(network, host)
	}
	return
}
Exemplo n.º 3
0
func LayerCBDialer(cb DialLayerCallback, d transport.Dialer) transport.Dialer {
	return transport.DialerFunc(func(network, address string) (net.Conn, error) {
		cb.Start()
		c, err := d.Dial(network, address)
		cb.Done(err)
		return c, err
	})
}
Exemplo n.º 4
0
func pingHost(
	dialer transport.Dialer,
	host string,
	timeout time.Duration,
	validator ConnCheck,
) (common.MapStr, reason.Reason) {
	start := time.Now()
	deadline := start.Add(timeout)

	conn, err := dialer.Dial("tcp", host)
	if err != nil {
		debugf("dial failed with: %v", err)
		return nil, reason.IOFailed(err)
	}
	defer conn.Close()
	if validator == nil {
		// no additional validation step => ping success
		return common.MapStr{}, nil
	}

	if err := conn.SetDeadline(deadline); err != nil {
		debugf("setting connection deadline failed with: %v", err)
		return nil, reason.IOFailed(err)
	}

	validateStart := time.Now()
	err = validator.Validate(conn)
	if err != nil && err != errRecvMismatch {
		debugf("check failed with: %v", err)
		return nil, reason.IOFailed(err)
	}

	end := time.Now()
	event := common.MapStr{
		"validate_rtt": look.RTT(end.Sub(validateStart)),
	}
	if err != nil {
		event["error"] = reason.FailValidate(err)
	}
	return event, nil
}
Exemplo n.º 5
0
func LayerDeltaCBDialer(
	cb DialLayerCallback,
	dialer transport.Dialer,
	layer func(transport.Dialer) (transport.Dialer, error),
) (transport.DialerFunc, error) {
	starter := transport.DialerFunc(func(network, address string) (net.Conn, error) {
		c, err := dialer.Dial(network, address)
		cb.Start()
		return c, err
	})

	layerInstance, err := layer(starter)
	if err != nil {
		return nil, err
	}

	return func(network, address string) (net.Conn, error) {
		c, err := layerInstance.Dial(network, address)
		cb.Done(err)
		return c, err
	}, nil
}