* fix: prevent duplicate call link detection (#23)

Co-authored-by: Maksim <maksim@MacBook-Pro-Maksim.local>

* bot improvements (#25)

Co-authored-by: Maksim <maksim@MBP-Maksim.lan>

* headless vk video creator

* add scroll to logs

* allow peer reconnection

* add todo about topology changes, kick stale peer to prevent SFU topology

* unified relay for headless

* remove relay binaries, extend build-go.sh to build them

* refactor constants

* limit headless resource usage

* nuke everyone and yourself at sfu topology changes

* add headless for creator

* save bot enabled state

* increment release version

---------

Co-authored-by: Nevenuga <80585376+Nevenuga@users.noreply.github.com>
Co-authored-by: Maksim <maksim@MacBook-Pro-Maksim.local>
Co-authored-by: Maksim <maksim@MBP-Maksim.lan>
Co-authored-by: kulikov <user@Mac.lan>
This commit is contained in:
authored and GitHub committed 2026-04-02 22:52:56 +02:00
1 parent d6a98e84ee
commit c8e1ba444d
37 files changed
+2589 -133

No files matched your search

+38 -29
View File
@@ -9,6 +9,8 @@ import (
"sync"
"sync/atomic"
"time"
"whitelist-bypass/relay/socks"
)
const (
@@ -148,14 +150,16 @@ func (rb *RelayBridge) handleCreatorMessage(connID uint32, msgType byte, payload
case msgUDP:
go rb.handleUDP(connID, payload)
case msgData:
val, ok := rb.conns.Load(connID)
if ok {
val.(net.Conn).Write(payload)
if val, ok := rb.conns.Load(connID); ok {
if c, ok := val.(net.Conn); ok {
c.Write(payload)
}
}
case msgClose:
val, ok := rb.conns.LoadAndDelete(connID)
if ok {
val.(net.Conn).Close()
if val, ok := rb.conns.LoadAndDelete(connID); ok {
if c, ok := val.(net.Conn); ok {
c.Close()
}
}
}
}
@@ -184,7 +188,7 @@ func (rb *RelayBridge) handleUDP(connID uint32, payload []byte) {
defer conn.Close()
conn.SetDeadline(time.Now().Add(5 * time.Second))
conn.Write(data)
buf := make([]byte, 4096)
buf := make([]byte, socks.UDPBufSize)
n, err := conn.Read(buf)
if err != nil {
return
@@ -204,7 +208,7 @@ func (rb *RelayBridge) connectTCP(connID uint32, addr string) {
rb.send(connID, msgConnectOK, nil)
rb.logFn("relay: CONNECTED %d -> %s", connID, maskAddr(addr))
buf := make([]byte, 900)
buf := make([]byte, socks.VP8BufSize)
for {
n, err := conn.Read(buf)
if n > 0 {
@@ -247,38 +251,38 @@ func (rb *RelayBridge) ListenSOCKS(addr string) error {
func (rb *RelayBridge) handleSOCKS(conn net.Conn) {
<-rb.ready
buf := make([]byte, 258)
buf := make([]byte, socks.HandshakeBuf)
n, err := conn.Read(buf)
if err != nil || n < 2 || buf[0] != 0x05 {
if err != nil || n < 2 || buf[0] != socks.Ver {
conn.Close()
return
}
conn.Write([]byte{0x05, 0x00})
conn.Write(socks.NoAuth)
n, err = conn.Read(buf)
if err != nil || n < 7 || buf[0] != 0x05 {
if err != nil || n < 7 || buf[0] != socks.Ver {
conn.Close()
return
}
cmd := buf[1]
if cmd == 0x03 {
if cmd == socks.CmdUDP {
rb.handleUDPAssociate(conn)
return
}
if cmd != 0x01 {
conn.Write([]byte{0x05, 0x07, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
if cmd != socks.CmdTCP {
conn.Write(socks.CmdErr)
conn.Close()
return
}
var host string
switch buf[3] {
case 0x01:
case socks.AtypIPv4:
if n < 10 {
conn.Close()
return
}
host = fmt.Sprintf("%d.%d.%d.%d:%d", buf[4], buf[5], buf[6], buf[7],
binary.BigEndian.Uint16(buf[8:10]))
case 0x03:
case socks.AtypDomain:
dlen := int(buf[4])
if n < 5+dlen+2 {
conn.Close()
@@ -286,7 +290,7 @@ func (rb *RelayBridge) handleSOCKS(conn net.Conn) {
}
host = fmt.Sprintf("%s:%d", string(buf[5:5+dlen]),
binary.BigEndian.Uint16(buf[5+dlen:7+dlen]))
case 0x04:
case socks.AtypIPv6:
if n < 22 {
conn.Close()
return
@@ -295,7 +299,7 @@ func (rb *RelayBridge) handleSOCKS(conn net.Conn) {
host = fmt.Sprintf("[%s]:%d", ip.String(),
binary.BigEndian.Uint16(buf[20:22]))
default:
conn.Write([]byte{0x05, 0x08, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
conn.Write(socks.AddrErr)
conn.Close()
return
}
@@ -308,16 +312,16 @@ func (rb *RelayBridge) handleSOCKS(conn net.Conn) {
if err := <-sc.rdy; err != nil {
rb.logFn("relay: SOCKS CONNECT %d failed: %v", id, err)
conn.Write([]byte{0x05, 0x05, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
conn.Write(socks.ConnFail)
conn.Close()
rb.conns.Delete(id)
return
}
conn.Write([]byte{0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
conn.Write(socks.OK)
rb.logFn("relay: SOCKS CONNECTED %d -> %s", id, maskAddr(host))
go func() {
readBuf := make([]byte, 900)
readBuf := make([]byte, socks.VP8BufSize)
for {
rn, rerr := conn.Read(readBuf)
if rn > 0 {
@@ -333,15 +337,20 @@ func (rb *RelayBridge) handleSOCKS(conn net.Conn) {
}
func (rb *RelayBridge) handleUDPAssociate(tcpConn net.Conn) {
udpAddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:0")
udpAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0")
if err != nil {
tcpConn.Write(socks.GenFail)
tcpConn.Close()
return
}
udpConn, err := net.ListenUDP("udp", udpAddr)
if err != nil {
tcpConn.Write([]byte{0x05, 0x01, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
tcpConn.Write(socks.GenFail)
tcpConn.Close()
return
}
localAddr := udpConn.LocalAddr().(*net.UDPAddr)
reply := []byte{0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0, 0}
reply := []byte{socks.Ver, 0x00, 0x00, socks.AtypIPv4, 127, 0, 0, 1, 0, 0}
binary.BigEndian.PutUint16(reply[8:10], uint16(localAddr.Port))
tcpConn.Write(reply)
@@ -354,7 +363,7 @@ func (rb *RelayBridge) handleUDPAssociate(tcpConn net.Conn) {
go func() {
defer udpConn.Close()
defer tcpConn.Close()
buf := make([]byte, 4096)
buf := make([]byte, socks.UDPBufSize)
for {
n, addr, err := udpConn.ReadFromUDP(buf)
if err != nil {
@@ -371,14 +380,14 @@ func (rb *RelayBridge) handleUDPAssociate(tcpConn net.Conn) {
var dstAddr string
var headerLen int
switch atyp {
case 0x01:
case socks.AtypIPv4:
if n < 10 {
continue
}
dstAddr = fmt.Sprintf("%d.%d.%d.%d:%d", buf[4], buf[5], buf[6], buf[7],
binary.BigEndian.Uint16(buf[8:10]))
headerLen = 10
case 0x03:
case socks.AtypDomain:
dlen := int(buf[4])
if n < 5+dlen+2 {
continue
@@ -386,7 +395,7 @@ func (rb *RelayBridge) handleUDPAssociate(tcpConn net.Conn) {
dstAddr = fmt.Sprintf("%s:%d", string(buf[5:5+dlen]),
binary.BigEndian.Uint16(buf[5+dlen:7+dlen]))
headerLen = 5 + dlen + 2
case 0x04:
case socks.AtypIPv6:
if n < 22 {
continue
}