Created
September 20, 2022 00:46
-
-
Save u-r-w/e594d3df693733118bf3f67612caed19 to your computer and use it in GitHub Desktop.
A simplified (not executable) Go websocket ActiveClients map value that prove a point about encoded-complexity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make a map containing clients | |
ActiveClients = make(map[ClientConn]int) | |
type ClientConn struct { | |
websocket *websocket.Conn | |
clientIP string | |
} | |
client := ws.Request().RemoteAddr | |
sockCli := ClientConn{ws, client} | |
ActiveClients[sockCli] = 0 | |
// Result | |
map[main.ClientConn]int{{ | |
websocket: &websocket.Conn{ | |
config: &websocket.Config{ | |
Location: &url.URL{ | |
Scheme: "ws", | |
Opaque: "", | |
User: (*url.Userinfo)(nil), | |
Host: "localhost:8000", | |
Path: "/sock", | |
RawPath: "", | |
ForceQuery: false, | |
RawQuery: "", | |
Fragment: "", | |
RawFragment: "", | |
}, | |
Origin: &url.URL{ | |
Scheme: "http", | |
Opaque: "", | |
User: (*url.Userinfo)(nil), | |
Host: "localhost:8000", | |
Path: "", | |
RawPath: "", | |
ForceQuery: false, | |
RawQuery: "", | |
Fragment: "", | |
RawFragment: "", | |
}, | |
Protocol: nil, | |
Version: 13, | |
TlsConfig: (*tls.Config)(nil), | |
Header: {}, | |
Dialer: (*net.Dialer)(nil), | |
handshakeData: {}, | |
}, | |
request: &http.Request{ | |
Method: "GET", | |
URL: &url.URL{ | |
Scheme: "", | |
Opaque: "", | |
User: (*url.Userinfo)(nil), | |
Host: "", | |
Path: "/sock", | |
RawPath: "", | |
ForceQuery: false, | |
RawQuery: "", | |
Fragment: "", | |
RawFragment: "", | |
}, | |
Proto: "HTTP/1.1", | |
ProtoMajor: 1, | |
ProtoMinor: 1, | |
Header: { | |
"Accept-Encoding": {"gzip, deflate, br"}, | |
"Accept-Language": {"en-US,en;q=0.9,id;q=0.8,sv;q=0.7"}, | |
"Cache-Control": {"no-cache"}, | |
"Connection": {"Upgrade"}, | |
"Cookie": {"prefsHttp={%22showAuthorshipColors%22:true%2C%22showAuthorColors%22:true}"}, | |
"Origin": {"http://localhost:8000"}, | |
"Pragma": {"no-cache"}, | |
"Sec-Websocket-Extensions": {"permessage-deflate; client_max_window_bits"}, | |
"Sec-Websocket-Key": {"HsCLNLyShx0sLvZn9ugCHQ=="}, | |
"Sec-Websocket-Version": {"13"}, | |
"Upgrade": {"websocket"}, | |
"User-Agent": {"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}, | |
}, | |
Body: http.noBody{}, | |
GetBody: func() (io.ReadCloser, error) {...}, | |
ContentLength: 0, | |
TransferEncoding: nil, | |
Close: false, | |
Host: "localhost:8000", | |
Form: {}, | |
PostForm: {}, | |
MultipartForm: (*multipart.Form)(nil), | |
Trailer: {}, | |
RemoteAddr: "[::1]:38348", | |
RequestURI: "/sock", | |
TLS: (*tls.ConnectionState)(nil), | |
Cancel: 0x0, | |
Response: (*http.Response)(nil), | |
ctx: &context.cancelCtx{ | |
Context: &context.cancelCtx{ | |
Context: &context.valueCtx{ | |
Context: &context.valueCtx{ | |
Context: &context.emptyCtx(0), | |
key: &http.contextKey{name:"http-server"}, | |
val: &http.Server{ | |
Addr: "0.0.0.0:8000", | |
Handler: nil, | |
TLSConfig: &tls.Config{ | |
Rand: nil, | |
Time: func() time.Time {...}, | |
Certificates: nil, | |
NameToCertificate: {}, | |
GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) {...}, | |
GetClientCertificate: func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {...}, | |
GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) {...}, | |
VerifyPeerCertificate: func([][]uint8, [][]*x509.Certificate) error {...}, | |
VerifyConnection: func(tls.ConnectionState) error {...}, | |
RootCAs: (*x509.CertPool)(nil), | |
NextProtos: {"h2"}, | |
ServerName: "", | |
ClientAuth: 0, | |
ClientCAs: (*x509.CertPool)(nil), | |
InsecureSkipVerify: false, | |
CipherSuites: nil, | |
PreferServerCipherSuites: true, | |
SessionTicketsDisabled: false, | |
SessionTicketKey: {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, | |
ClientSessionCache: nil, | |
MinVersion: 0x0, | |
MaxVersion: 0x0, | |
CurvePreferences: nil, | |
DynamicRecordSizingDisabled: false, | |
Renegotiation: 0, | |
KeyLogWriter: nil, | |
mutex: sync.RWMutex{}, | |
sessionTicketKeys: nil, | |
autoSessionTicketKeys: nil, | |
}, | |
ReadTimeout: 0, | |
ReadHeaderTimeout: 0, | |
WriteTimeout: 0, | |
IdleTimeout: 0, | |
MaxHeaderBytes: 0, | |
TLSNextProto: {"h2":func(*http.Server, *tls.Conn, http.Handler) {...}}, | |
ConnState: func(net.Conn, http.ConnState) {...}, | |
ErrorLog: (*log.Logger)(nil), | |
BaseContext: func(net.Listener) context.Context {...}, | |
ConnContext: func(context.Context, net.Conn) context.Context {...}, | |
inShutdown: 0, | |
disableKeepAlives: 0, | |
nextProtoOnce: sync.Once{ | |
done: 0x1, | |
m: sync.Mutex{}, | |
}, | |
nextProtoErr: nil, | |
mu: sync.Mutex{}, | |
listeners: { | |
&&http.onceCloseListener{ | |
Listener: &!%v(DEPTH EXCEEDED), | |
once: sync.Once{}, | |
closeErr: nil, | |
}: {}, | |
}, | |
activeConn: { | |
&http.conn{ | |
server: &http.Server{(CYCLIC REFERENCE)}, | |
cancelCtx: context.CancelFunc {...}, | |
rwc: &net.TCPConn{ | |
conn: net.conn{ | |
fd: &net.netFD{ | |
pfd: poll.FD{ | |
fdmu: poll.fdMutex{state:0xa, rsema:0x0, wsema:0x0}, | |
Sysfd: 7, | |
pd: poll.pollDesc{runtimeCtx:0x7f97302055f0}, | |
iovecs: (*[]syscall.Iovec)(nil), | |
csema: 0x0, | |
isBlocking: 0x0, | |
IsStream: true, | |
ZeroReadIsEOF: true, | |
isFile: false, | |
}, | |
family: 10, | |
sotype: 1, | |
isConnected: false, | |
net: "tcp", | |
laddr: &!%v(DEPTH EXCEEDED), | |
raddr: &!%v(DEPTH EXCEEDED), | |
}, | |
}, | |
}, | |
remoteAddr: "[::1]:38346", | |
tlsState: (*tls.ConnectionState)(nil), | |
werr: nil, | |
r: &http.connReader{ | |
conn: &http.conn{(CYCLIC REFERENCE)}, | |
mu: sync.Mutex{}, | |
hasByte: false, | |
byteBuf: {0x0}, | |
cond: &sync.Cond{ | |
noCopy: sync.noCopy{}, | |
L: &!%v(DEPTH EXCEEDED), | |
notify: sync.notifyList{wait:0x1, notify:0x1, lock:0x0, head:0x0, tail:0x0}, | |
checker: 0xc000060370, | |
}, | |
inRead: true, | |
aborted: false, | |
remain: 1052672, | |
}, | |
bufr: &bufio.Reader{ | |
buf: {0x47, 0x45, 0x54, 0x20, 0x2f} | |
}, | |
rd: &http.connReader{(CYCLIC REFERENCE)}, | |
r: 0, | |
w: 0, | |
err: nil, | |
lastByte: 10, | |
lastRuneSize: -1, | |
}, | |
bufw: &bufio.Writer{ | |
err: nil, | |
buf: {0x48, 0x54, 0x54, 0x50} | |
}, | |
n: 0, | |
wr: http.checkConnErrorWriter{ | |
c: &http.conn{(CYCLIC REFERENCE)}, | |
}, | |
}, | |
lastMethod: "GET", | |
curReq: atomic.Value{}, | |
curState: struct { atomic uint64 }{atomic:0x6328602b02}, | |
mu: sync.Mutex{}, | |
hijackedv: false, | |
}: {}, | |
}, | |
doneChan: 0x0, | |
onShutdown: {func() {...}}, | |
}, | |
}, | |
key: &http.contextKey{name:"local-addr"}, | |
val: &net.TCPAddr{ | |
IP: {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1}, | |
Port: 8000, | |
Zone: "", | |
}, | |
}, | |
mu: sync.Mutex{}, | |
done: 0xc00001e1e0, | |
children: { | |
&context.cancelCtx{(CYCLIC REFERENCE)}: {}, | |
}, | |
err: nil, | |
}, | |
mu: sync.Mutex{}, | |
done: 0x0, | |
children: {}, | |
err: nil, | |
}, | |
}, | |
buf: &bufio.ReadWriter{ | |
Reader: &bufio.Reader{ | |
buf: {0x81, 0xbc, 0xed, 0xb6, 0x19} | |
} | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment