Beispiel #1
0
func connectNewFramesClient(addr string) *frameClient {
	c, err := net.DialTimeout("tcp", addr, frameConnectTimeout)
	if err != nil {
		log.Printf("Error connecting to %v: %v", addr, err)
		return nil
	}
	conn := frames.NewClient(c)
	frt := &framesweb.FramesRoundTripper{
		Dialer:  conn,
		Timeout: time.Second * 5,
	}
	hc := &http.Client{Transport: frt}
	frameClientsLock.Lock()
	defer frameClientsLock.Unlock()

	fwc := &frameClient{
		conn:   conn,
		client: hc,
		checker: time.AfterFunc(frameCheckFreq, func() {
			checkFrameClient(addr)
		}),
	}
	frameClients[addr] = fwc
	return fwc
}
Beispiel #2
0
// NewFramesClient gets an HTTP client that maintains a persistent
// frames connection.
func NewFramesClient(n, addr string) (*http.Client, error) {
	c, err := net.Dial(n, addr)
	if err != nil {
		return nil, err
	}

	frt := &FramesRoundTripper{
		Dialer:  frames.NewClient(c),
		Timeout: time.Hour,
	}

	hc := &http.Client{
		Transport: frt,
	}

	return hc, nil
}
Beispiel #3
0
func (srv *Service) negotiateNewMuxConn(conn net.Conn) {
	// Deadline of 10s on mux negotiation.
	if err := conn.SetDeadline(time.Now().Add(10 * time.Second)); err != nil {
		srv.log.Printf("Could not set deadline on incoming mux connection - ignoring: %v", err)
	}

	srv.log.Printf("Got mux client %v, negotiating version", conn.RemoteAddr())
	// Protocol version.
	if err := muxcommon.ReadCheckVersion(conn); err != nil {
		conn.Close()
		srv.log.Printf("Error checking mux client version: %v", err)
		return
	}
	if err := muxcommon.SendVersion(conn); err != nil {
		conn.Close()
		srv.log.Printf("Error sending version: %v", err)
		return
	}

	// TODO: Authenticate connection before handing to muxMatcher.

	srv.log.Print("Setting up compression")
	// Set up compression on the data flowing from mux client to mux server.
	compConnRead, err := zlib.NewReader(conn)
	if err != nil {
		conn.Close()
		srv.log.Printf("Failed to initiate reading of compressed data on incoming mux connection: %v", err)
		return
	}

	// Negotiation complete.
	conn.SetDeadline(time.Time{})

	srv.log.Printf("New mux client connected from %v", conn.RemoteAddr())
	srv.newMuxConn <- frames.NewClient(&netutil.ConnWrapper{
		Reader:         compConnRead,
		Writer:         conn,
		UnderlyingConn: conn,
		ReadCloser:     compConnRead,
	})
}