mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
add singbox core(just started)
This commit is contained in:
58
core/sing/hook.go
Normal file
58
core/sing/hook.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package sing
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/counter"
|
||||
"github.com/inazumav/sing-box/adapter"
|
||||
"github.com/inazumav/sing-box/log"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
)
|
||||
|
||||
type HookServer struct {
|
||||
hooker *Hooker
|
||||
}
|
||||
|
||||
func NewHookServer(logger log.Logger) *HookServer {
|
||||
return &HookServer{
|
||||
hooker: &Hooker{
|
||||
logger: logger,
|
||||
counter: make(map[string]*counter.TrafficCounter),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HookServer) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *HookServer) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *HookServer) StatsService() adapter.V2RayStatsService {
|
||||
return h.hooker
|
||||
}
|
||||
|
||||
func (h *HookServer) Hooker() *Hooker {
|
||||
return h.hooker
|
||||
}
|
||||
|
||||
type Hooker struct {
|
||||
logger log.Logger
|
||||
counter map[string]*counter.TrafficCounter
|
||||
}
|
||||
|
||||
func (h *Hooker) RoutedConnection(inbound string, outbound string, user string, conn net.Conn) net.Conn {
|
||||
if c, ok := h.counter[inbound]; ok {
|
||||
return counter.NewConnCounter(conn, c.GetCounter(user))
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
||||
func (h *Hooker) RoutedPacketConnection(inbound string, outbound string, user string, conn N.PacketConn) N.PacketConn {
|
||||
if c, ok := h.counter[inbound]; ok {
|
||||
return counter.NewPacketConnCounter(conn, c.GetCounter(user))
|
||||
}
|
||||
return conn
|
||||
}
|
||||
Reference in New Issue
Block a user