mirror of
https://github.com/masterking32/MasterHttpRelayVPN.git
synced 2026-05-18 23:54:37 +03:00
Session based and stream data.
This commit is contained in:
@@ -8,6 +8,8 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
@@ -18,20 +20,24 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
cfg config.Config
|
||||
log *logger.Logger
|
||||
sessions *SessionStore
|
||||
cfg config.Config
|
||||
log *logger.Logger
|
||||
clientSessionKey string
|
||||
streams *StreamStore
|
||||
|
||||
connMu sync.Mutex
|
||||
conns map[net.Conn]struct{}
|
||||
}
|
||||
|
||||
func New(cfg config.Config, lg *logger.Logger) *Client {
|
||||
clientSessionKey := generateClientSessionKey()
|
||||
|
||||
return &Client{
|
||||
cfg: cfg,
|
||||
log: lg,
|
||||
sessions: NewSessionStore(),
|
||||
conns: make(map[net.Conn]struct{}),
|
||||
cfg: cfg,
|
||||
log: lg,
|
||||
clientSessionKey: clientSessionKey,
|
||||
streams: NewStreamStore(),
|
||||
conns: make(map[net.Conn]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +50,7 @@ func (c *Client) Run(ctx context.Context) error {
|
||||
defer ln.Close()
|
||||
|
||||
c.log.Infof("<green>SOCKS5 listener started on <cyan>%s</cyan></green>", addr)
|
||||
c.log.Infof("<green>client session key: <cyan>%s</cyan></green>", c.clientSessionKey)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
@@ -103,3 +110,13 @@ func (c *Client) closeAllConns() {
|
||||
_ = conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func generateClientSessionKey() string {
|
||||
now := time.Now().UTC().Format("20060102T150405.000000000Z")
|
||||
random := make([]byte, 16)
|
||||
if _, err := rand.Read(random); err != nil {
|
||||
return fmt.Sprintf("%s_fallback", now)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s_%s", now, hex.EncodeToString(random))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user