pupy/services/proxy/types.go

150 lines
2.4 KiB
Go
Raw Normal View History

2018-01-29 15:41:53 +00:00
package main
import (
"net"
"sync"
2018-01-29 15:41:53 +00:00
"time"
dns "github.com/miekg/dns"
rc "github.com/paulbellamy/ratecounter"
2018-01-29 15:41:53 +00:00
)
type (
Conn struct {
in chan []byte
out chan []byte
close chan bool
}
2019-09-27 08:02:14 +00:00
KCPConn struct {
net.Conn
localId [4]byte
remoteId [4]byte
initialized bool
new_sent bool
}
2018-01-29 15:41:53 +00:00
Listener struct {
Listener net.Listener
refcnt int
}
ListenerProtocol int
BindRequestType int
PortMap struct {
From int
To int
}
2018-01-29 15:41:53 +00:00
BindRequestHeader struct {
Protocol ListenerProtocol `msgpack:"prot"`
BindInfo string `msgpack:"bind"`
Timeout int `msgpack:"timeout"`
2019-10-03 16:37:11 +00:00
MTU int `msgpack:"mtu"`
2018-01-29 15:41:53 +00:00
}
DNSRequest struct {
Name string
2019-03-10 15:40:40 +00:00
Type string
2018-01-29 15:41:53 +00:00
IPs chan []string
}
DNSCacheRecord struct {
ResponseRecords []dns.RR
LastActivity time.Time
}
ConnectionAcceptHeader struct {
2018-01-30 13:44:55 +00:00
Extra bool `msgpack:"extra"`
2018-01-29 15:41:53 +00:00
LocalHost string `msgpack:"lhost"`
LocalPort int `msgpack:"lport"`
RemoteHost string `msgpack:"rhost"`
RemotePort int `msgpack:"rport"`
Error string `msgpack:"error"`
}
DNSListener struct {
Conn net.Conn
Domain string
DNSCache map[string]*DNSCacheRecord
UDPServer *dns.Server
TCPServer *dns.Server
DNSRequests chan *DNSRequest
processedRequests sync.WaitGroup
dnsRequestsCounter *rc.RateCounter
dnsRemoteRequestsCounter *rc.RateCounter
dnsProcessedRequestsCounter *rc.RateCounter
2018-01-30 19:54:32 +00:00
cacheLock sync.Mutex
activeLock sync.Mutex
active bool
pendingRequests int32
2018-01-29 15:41:53 +00:00
}
Daemon struct {
Addr string
DNSLock sync.Mutex
DNSCheck sync.Mutex
DNSListener *DNSListener
Listeners map[int]*Listener
ListenersLock sync.Mutex
UsersCount int32
2018-01-29 15:41:53 +00:00
}
2018-01-30 13:44:55 +00:00
2018-01-30 14:10:54 +00:00
IPInfo struct {
IP string `msgpack:"ip"`
}
2018-01-30 13:44:55 +00:00
Extra struct {
Extra bool `msgpack:"extra"`
Data string `msgpack:"data"`
}
TLSAcceptorConfig struct {
CACert string `msgpack:"ca"`
Cert string `msgpack:"cert"`
Key string `msgpack:"key"`
}
2019-10-03 16:37:11 +00:00
KeepAlive struct {
Tick int64 `msgpack:"keepalive"`
Last bool `msgpack:"last"`
}
NetReader struct {
mtu int
in net.Conn
out net.Conn
err error
wait chan error
}
NetForwarder struct {
pproxy net.Conn
remote net.Conn
}
2018-01-29 15:41:53 +00:00
)
const (
2018-01-30 14:10:54 +00:00
INFO ListenerProtocol = 0
DNS ListenerProtocol = iota
TCP ListenerProtocol = iota
KCP ListenerProtocol = iota
TLS ListenerProtocol = iota
2019-09-27 08:02:14 +00:00
KCP_NEW = 0x0
KCP_DAT = 0x1
KCP_END = 0x2
2018-01-29 15:41:53 +00:00
)