add sshd listener

This commit is contained in:
ginuerzh
2022-01-26 15:53:33 +08:00
parent a134026e76
commit 04dfc8c4c3
39 changed files with 1101 additions and 848 deletions

View File

@ -12,8 +12,8 @@ import (
"github.com/go-gost/gost/pkg/logger"
)
func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, address string) {
h.logger = h.logger.WithFields(map[string]interface{}{
func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
log = log.WithFields(map[string]interface{}{
"cmd": "udp",
})
@ -30,49 +30,47 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, add
resp.StatusCode = http.StatusForbidden
resp.Write(conn)
if h.logger.IsLevelEnabled(logger.DebugLevel) {
if log.IsLevelEnabled(logger.DebugLevel) {
dump, _ := httputil.DumpResponse(resp, false)
h.logger.Debug(string(dump))
log.Debug(string(dump))
}
h.logger.Error("UDP relay is diabled")
log.Error("UDP relay is diabled")
return
}
resp.StatusCode = http.StatusOK
if h.logger.IsLevelEnabled(logger.DebugLevel) {
if log.IsLevelEnabled(logger.DebugLevel) {
dump, _ := httputil.DumpResponse(resp, false)
h.logger.Debug(string(dump))
log.Debug(string(dump))
}
if err := resp.Write(conn); err != nil {
h.logger.Error(err)
log.Error(err)
return
}
// obtain a udp connection
c, err := h.router.Dial(ctx, "udp", "") // UDP association
if err != nil {
h.logger.Error(err)
log.Error(err)
return
}
defer c.Close()
pc, ok := c.(net.PacketConn)
if !ok {
h.logger.Errorf("wrong connection type")
log.Errorf("wrong connection type")
return
}
relay := handler.NewUDPRelay(socks.UDPTunServerConn(conn), pc).
WithBypass(h.options.Bypass).
WithLogger(h.logger)
WithLogger(log)
t := time.Now()
h.logger.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
relay.Run()
h.logger.
WithFields(map[string]interface{}{
"duration": time.Since(t),
}).
Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
log.WithFields(map[string]interface{}{
"duration": time.Since(t),
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
}