migrate to go module; ignore more irrelevant code at the wasm side
This commit is contained in:
parent
f937a7ae3e
commit
d772b82e94
2
addr.go
2
addr.go
|
@ -1,4 +1,4 @@
|
|||
package zocket /* import "udico.de/dreem/zocket" */
|
||||
package zocket
|
||||
|
||||
// Addr represents a (the) WebSocket end point address.
|
||||
// Since WebSocket connections are upgraded HTTP Connections,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build js, wasm
|
||||
//go:build js && wasm
|
||||
|
||||
package zocket /* import "udico.de/dreem/zocket" */
|
||||
package zocket
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -17,12 +17,12 @@ type handler func(this js.Value, args []js.Value) interface{}
|
|||
|
||||
// ClientConnection is a TCP like Connection between the wasm and a server.
|
||||
type ClientConnection struct {
|
||||
M sync.Mutex
|
||||
ws js.Value
|
||||
conn chan struct{}
|
||||
in chan []byte
|
||||
M sync.Mutex
|
||||
ws js.Value
|
||||
conn chan struct{}
|
||||
in chan []byte
|
||||
onMessage handler
|
||||
buffered []byte
|
||||
buffered []byte
|
||||
}
|
||||
|
||||
func makeHandler(c chan []byte) handler {
|
||||
|
@ -43,8 +43,8 @@ func makeHandler(c chan []byte) handler {
|
|||
func Dial(ctx context.Context, target string) (net.Conn, error) {
|
||||
fmt.Printf("dialing %v\n", target)
|
||||
ret := ClientConnection{
|
||||
ws: js.Global().Get("WebSocket").New(target),
|
||||
in: make(chan []byte),
|
||||
ws: js.Global().Get("WebSocket").New(target),
|
||||
in: make(chan []byte),
|
||||
conn: make(chan struct{}),
|
||||
}
|
||||
ret.ws.Set("binaryType", "arraybuffer")
|
||||
|
@ -80,7 +80,6 @@ func Dial(ctx context.Context, target string) (net.Conn, error) {
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
// Read gets some bytes from a ws frame. Blocks.
|
||||
func (c ClientConnection) Read(b []byte) (int, error) {
|
||||
fmt.Println("client_read")
|
||||
|
@ -138,7 +137,7 @@ func (c ClientConnection) Close() error {
|
|||
// dummy and make underlying layers think they're using a tcp conection.
|
||||
func (c ClientConnection) LocalAddr() net.Addr {
|
||||
fmt.Println("DBG: call LocalAddr() on ClientConnection")
|
||||
return Addr {
|
||||
return Addr{
|
||||
network: "tcp",
|
||||
address: "0.0.0.0",
|
||||
}
|
||||
|
@ -147,7 +146,7 @@ func (c ClientConnection) LocalAddr() net.Addr {
|
|||
// RemoteAddr returns the adress of the remote endpoint.
|
||||
func (c ClientConnection) RemoteAddr() net.Addr {
|
||||
fmt.Println("DBG: call RemoteAddr() on ClientConnection")
|
||||
return Addr {
|
||||
return Addr{
|
||||
network: "tcp",
|
||||
// TODO: Use the real servers adress somehow (or none at all? :think:)
|
||||
address: "127.0.0.1",
|
||||
|
|
5
doc.go
5
doc.go
|
@ -1,3 +1,2 @@
|
|||
// Zocket transparently tunnels a TCP connection through a WebSocket layer from within WebAssembly.
|
||||
|
||||
package zocket /* import "udico.de/dreem/zocket" */
|
||||
// Package zocket transparently tunnels a TCP connection through a WebSocket layer from within WebAssembly.
|
||||
package zocket
|
||||
|
|
8
frame.go
8
frame.go
|
@ -1,4 +1,6 @@
|
|||
package zocket /* import "udico.de/dreem/zocket" */
|
||||
//go:build !js && !wasm
|
||||
|
||||
package zocket
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
@ -19,7 +21,7 @@ const (
|
|||
)
|
||||
|
||||
/*
|
||||
*
|
||||
* Frame
|
||||
*/
|
||||
type Frame struct {
|
||||
Fin bool
|
||||
|
@ -158,4 +160,4 @@ func (f *Frame) WriteTo(conn net.Conn) error {
|
|||
l += n
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
7
go.mod
Normal file
7
go.mod
Normal file
|
@ -0,0 +1,7 @@
|
|||
module udico.de/dreem/zocket
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/sirupsen/logrus v1.9.0
|
||||
|
||||
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
15
go.sum
Normal file
15
go.sum
Normal file
|
@ -0,0 +1,15 @@
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
20
listener.go
20
listener.go
|
@ -1,4 +1,6 @@
|
|||
package zocket /* import "udico.de/dreem/zocket" */
|
||||
//go:build !js || !wasm
|
||||
|
||||
package zocket
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
|
@ -48,14 +50,14 @@ func (l Listener) Accept() (net.Conn, error) {
|
|||
// Any blocked Accept operations will be unblocked and return errors.
|
||||
func (l Listener) Close() error {
|
||||
select {
|
||||
case _, ok := <-l.cConn:
|
||||
// either the channel closed or we just read a connection from it.
|
||||
// we discard the connection, since we're about to close the channel anyways
|
||||
if !ok {
|
||||
return errors.New("channel already closed")
|
||||
}
|
||||
default:
|
||||
// something blocks. the channel is alive
|
||||
case _, ok := <-l.cConn:
|
||||
// either the channel closed or we just read a connection from it.
|
||||
// we discard the connection, since we're about to close the channel anyways
|
||||
if !ok {
|
||||
return errors.New("channel already closed")
|
||||
}
|
||||
default:
|
||||
// something blocks. the channel is alive
|
||||
}
|
||||
close(l.cConn)
|
||||
return nil
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
package zocket /* import "udico.de/dreem/zocket" */
|
||||
//go:build !js || !wasm
|
||||
|
||||
package zocket
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -11,7 +13,7 @@ import (
|
|||
|
||||
// ServerConnection is the serverside part of the ws abstraction
|
||||
type ServerConnection struct {
|
||||
conn net.Conn // The underlying REAL connection.
|
||||
conn net.Conn // The underlying REAL connection.
|
||||
buffered []byte
|
||||
}
|
||||
|
||||
|
@ -30,13 +32,13 @@ func (c ServerConnection) Read(b []byte) (int, error) {
|
|||
}
|
||||
return len(b), nil
|
||||
}
|
||||
buf := &bytes.Buffer{}//
|
||||
datloop:
|
||||
buf := &bytes.Buffer{} //
|
||||
datloop:
|
||||
for {
|
||||
tFrame, err := ReadFrame(c.conn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
switch tFrame.Opcode {
|
||||
case FrameType_Ping:
|
||||
// send pong
|
||||
|
|
Loading…
Reference in New Issue
Block a user