log
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -12,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type TunnelConnection struct {
|
||||
@@ -51,7 +51,7 @@ func (s *Server) Start(addr string) error {
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
log.Printf("Conduit server listening on %s", addr)
|
||||
log.Infof("Conduit server listening on %s", addr)
|
||||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
@@ -120,7 +120,7 @@ func (s *Server) proxyRawConnection(clientConn net.Conn, tunnelConn *TunnelConne
|
||||
}
|
||||
|
||||
if err := tunnelConn.WriteJSON(msg); err != nil {
|
||||
log.Printf("Error sending initial data: %v", err)
|
||||
log.Errorf("Error sending initial data: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ func (s *Server) handleRawConnection(conn net.Conn) {
|
||||
s.mu.RUnlock()
|
||||
|
||||
if exists {
|
||||
log.Printf("Relaying %s to tunnel", subdomain)
|
||||
log.Infof("Relaying %s to tunnel", subdomain)
|
||||
s.proxyRawConnection(conn, tunnelConn, buffer[:n])
|
||||
return
|
||||
}
|
||||
@@ -219,12 +219,14 @@ func (s *Server) handleAsHTTP(conn net.Conn, initialData []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
// Handle control endpoints
|
||||
if req.URL.Path == "/_conduit/tunnel" {
|
||||
// Handle Control Endpoints
|
||||
switch req.URL.Path {
|
||||
case "/_conduit/tunnel":
|
||||
s.handleTunnelUpgrade(conn, req)
|
||||
} else if req.URL.Path == "/_conduit/status" {
|
||||
return
|
||||
case "/_conduit/status":
|
||||
s.handleStatus(conn)
|
||||
} else {
|
||||
default:
|
||||
conn.Write([]byte("HTTP/1.1 404 Not Found\r\n\r\n"))
|
||||
}
|
||||
}
|
||||
@@ -244,7 +246,7 @@ func (s *Server) handleTunnelMessages(tunnel *TunnelConnection) {
|
||||
select {
|
||||
case streamChan <- msg.Data:
|
||||
case <-time.After(time.Second):
|
||||
log.Printf("Stream %s channel full, dropping data", msg.StreamID)
|
||||
log.Infof("Stream %s channel full, dropping data", msg.StreamID)
|
||||
}
|
||||
}
|
||||
s.mu.RUnlock()
|
||||
@@ -264,7 +266,7 @@ func (s *Server) handleTunnelUpgrade(conn net.Conn, req *http.Request) {
|
||||
// Use the upgrader
|
||||
wsConn, err := s.upgrader.Upgrade(fakeWriter, req, nil)
|
||||
if err != nil {
|
||||
log.Printf("WebSocket upgrade failed: %v", err)
|
||||
log.Errorf("WebSocket upgrade failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -279,7 +281,7 @@ func (s *Server) handleTunnelUpgrade(conn net.Conn, req *http.Request) {
|
||||
s.tunnels[vhost] = tunnel
|
||||
s.mu.Unlock()
|
||||
|
||||
log.Printf("Tunnel established: %s", vhost)
|
||||
log.Infof("Tunnel established: %s", vhost)
|
||||
|
||||
// Keep connection alive and handle cleanup
|
||||
defer func() {
|
||||
@@ -287,7 +289,7 @@ func (s *Server) handleTunnelUpgrade(conn net.Conn, req *http.Request) {
|
||||
delete(s.tunnels, vhost)
|
||||
s.mu.Unlock()
|
||||
wsConn.Close()
|
||||
log.Printf("Tunnel closed: %s", vhost)
|
||||
log.Infof("Tunnel closed: %s", vhost)
|
||||
}()
|
||||
|
||||
// Handle tunnel messages
|
||||
|
||||
Reference in New Issue
Block a user