Merge pull request #13 from openlibrecommunity/refactor/all

Refactor/all
This commit is contained in:
zarazaex
2026-04-12 23:17:32 +03:00
committed by GitHub
5 changed files with 6 additions and 25 deletions

View File

@@ -28,7 +28,6 @@ type config struct {
keyHex string
debug bool
dataDir string
duo bool
dnsServer string
socksProxyAddr string
socksProxyPort int
@@ -94,7 +93,6 @@ func parseFlags() config {
flag.StringVar(&cfg.keyHex, "key", "", "Shared encryption key (hex)")
flag.BoolVar(&cfg.debug, "debug", false, "Enable verbose logging")
flag.StringVar(&cfg.dataDir, "data", "data", "Path to data directory")
flag.BoolVar(&cfg.duo, "duo", false, "Use dual channels for 2x throughput")
flag.StringVar(&cfg.dnsServer, "dns", "1.1.1.1:53", "DNS server (default: Cloudflare 1.1.1.1)")
flag.StringVar(&cfg.socksProxyAddr, "socks-proxy", "", "SOCKS5 proxy address (server only)")
flag.IntVar(&cfg.socksProxyPort, "socks-proxy-port", 1080, "SOCKS5 proxy port (server only)")
@@ -158,7 +156,6 @@ func runMode(ctx context.Context, cfg config, errCh chan<- error) {
ctx,
roomURL,
cfg.keyHex,
cfg.duo,
cfg.dnsServer,
cfg.socksProxyAddr,
cfg.socksProxyPort,
@@ -169,7 +166,6 @@ func runMode(ctx context.Context, cfg config, errCh chan<- error) {
roomURL,
cfg.keyHex,
cfg.socksPort,
cfg.duo,
cfg.socksHost,
"",
"",

View File

@@ -49,12 +49,11 @@ func Run(
roomURL,
keyHex string,
socksPort int,
duo bool,
socksHost,
socksUser,
socksPass string,
) error {
return RunWithReady(ctx, roomURL, keyHex, socksPort, duo, socksHost, socksUser, socksPass, nil)
return RunWithReady(ctx, roomURL, keyHex, socksPort, socksHost, socksUser, socksPass, nil)
}
// RunWithReady starts the client and invokes onReady once the local SOCKS5 listener is accepting connections.
@@ -63,7 +62,6 @@ func RunWithReady(
roomURL,
keyHex string,
socksPort int,
duo bool,
socksHost,
socksUser,
socksPass string,
@@ -90,12 +88,12 @@ func RunWithReady(
c := &Client{
cipher: cipher,
clientID: uint32(time.Now().UnixNano() & 0xFFFFFFFF),
peers: make([]*telemost.Peer, 0, peerCount(duo)),
peers: make([]*telemost.Peer, 0, 1),
}
c.mux = mux.New(c.clientID, c.sendFrame)
for peerID := range peerCount(duo) {
for peerID := range 1 {
if err := c.addPeer(runCtx, roomURL, peerID, cancel); err != nil {
return err
}
@@ -113,12 +111,7 @@ func RunWithReady(
return err
}
func peerCount(duo bool) int {
if duo {
log.Println("Duo mode: using 2 parallel channels")
return 2
}
func peerCount() int {
return 1
}

View File

@@ -45,7 +45,7 @@ type ConnectRequest struct {
Port int `json:"port"`
}
func Run(ctx context.Context, roomURL, keyHex string, duo bool, dnsServer, socksProxyAddr string, socksProxyPort int) error {
func Run(ctx context.Context, roomURL, keyHex string, dnsServer, socksProxyAddr string, socksProxyPort int) error {
runCtx, cancel := context.WithCancel(ctx)
defer cancel()
var key []byte
@@ -100,10 +100,6 @@ func Run(ctx context.Context, roomURL, keyHex string, duo bool, dnsServer, socks
}
peerCount := 1
if duo {
peerCount = 2
log.Println("Duo mode: using 2 parallel channels")
}
s.mux = mux.New(0, func(frame []byte) error {
for {

View File

@@ -1041,8 +1041,6 @@ func (p *Peer) WatchConnection(ctx context.Context) {
}
func (p *Peer) processSendQueue(workerID int, sessionCloseCh <-chan struct{}) {
log.Printf("[WORKER-%d] Started", workerID)
defer log.Printf("[WORKER-%d] Stopped", workerID)
for {
select {

View File

@@ -77,9 +77,8 @@ func SetDebug(enabled bool) {
// roomID: Telemost room ID (e.g. "xxx-xxx-xxx")
// keyHex: 64-char hex encryption key
// socksPort: local SOCKS5 proxy port (e.g. 10808)
// duo: use dual channels for higher throughput
// socksUser/socksPass: SOCKS5 credentials (empty = no auth).
func Start(roomID, keyHex string, socksPort int, duo bool, socksUser, socksPass string) error {
func Start(roomID, keyHex string, socksPort int, socksUser, socksPass string) error {
mu.Lock()
defer mu.Unlock()
@@ -110,7 +109,6 @@ func Start(roomID, keyHex string, socksPort int, duo bool, socksUser, socksPass
roomURL,
keyHex,
socksPort,
duo,
"",
socksUser,
socksPass,