Beispiel #1
0
// Dial retuns a (reused/reusable) connection to a keyless server.
func (c *Client) Dial(server string) (*gokeyless.Conn, error) {
	if c.Config == nil {
		return nil, errors.New("gokeyless/client: TLS client has not yet been initialized with certificate and keyserver CA")
	}

	c.m.RLock()
	conn, ok := c.conns[server]
	c.m.RUnlock()
	if ok {
		if conn.Use() {
			return conn, nil
		}
		c.m.Lock()
		if c.conns[server] == conn {
			delete(c.conns, server)
		}
		c.m.Unlock()
	}

	log.Debugf("Dialing %s\n", server)
	inner, err := tls.Dial("tcp", server, c.Config)
	if err != nil {
		return nil, err
	}

	c.m.Lock()
	defer c.m.Unlock()
	c.conns[server] = gokeyless.NewConn(inner)
	return c.conns[server], nil
}
Beispiel #2
0
// Serve accepts incoming connections on the Listener l, creating a new service goroutine for each.
func (s *Server) Serve(l net.Listener) error {
	defer l.Close()
	for {
		if c, err := l.Accept(); err != nil {
			log.Error(err)
		} else {
			go s.handle(gokeyless.NewConn(tls.Server(c, s.Config)))
		}
	}
}
Beispiel #3
0
// Serve accepts incoming connections on the Listener l, creating a new service goroutine for each.
func (s *Server) Serve(l net.Listener) error {
	defer l.Close()
	for {
		c, err := l.Accept()
		if err != nil {
			return err
		}

		go s.handle(gokeyless.NewConn(tls.Server(c, s.Config)))
	}

}
Beispiel #4
0
// Dial dials a remote server, returning an existing connection if possible.
func (s *server) Dial(c *Client) (*gokeyless.Conn, error) {
	if c.Blacklist.Contains(s) {
		return nil, fmt.Errorf("server %s on client blacklist", s.String())
	}

	if s.conn != nil && s.conn.Use() {
		return s.conn, nil
	}

	config := *c.Config
	config.ServerName = s.ServerName
	log.Debugf("Dialing %s at %s\n", s.ServerName, s.String())
	inner, err := tls.DialWithDialer(c.Dialer, s.Network(), s.String(), &config)
	if err != nil {
		return nil, err
	}

	s.conn = gokeyless.NewConn(inner)
	return s.conn, nil
}
Beispiel #5
0
// Dial retuns a (reused/reusable) connection to a keyless server.
func (c *Client) Dial(server string) (*gokeyless.Conn, error) {
	if c.Config == nil {
		return nil, errors.New("gokeyless/client: TLS client has not yet been initialized with certificate and keyserver CA")
	}

	if conn, ok := c.conns[server]; ok && conn.IsOpen {
		return conn, nil
	} else if ok {
		delete(c.conns, server)
	}

	c.Log.Printf("Dialing %s\n", server)
	conn, err := tls.Dial("tcp", server, c.Config)
	if err != nil {
		return nil, err
	}

	c.conns[server] = gokeyless.NewConn(conn)
	return c.conns[server], nil
}