-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gaukas Wang <[email protected]>
- Loading branch information
Showing
23 changed files
with
581 additions
and
488 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
v1 "github.com/refraction-networking/watm/tinygo/v1" | ||
v1net "github.com/refraction-networking/watm/tinygo/v1/net" | ||
) | ||
|
||
// type guard | ||
var _ v1.ListeningTransport = (*PlainListeningTransport)(nil) | ||
|
||
type PlainListeningTransport struct { | ||
listener v1net.Listener | ||
} | ||
|
||
func (lt *PlainListeningTransport) SetListener(listener v1net.Listener) { | ||
lt.listener = listener | ||
} | ||
|
||
func (lt *PlainListeningTransport) Accept() (v1net.Conn, error) { | ||
conn, err := lt.listener.Accept() // accept the connection | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &PlainConn{conn}, conn.SetNonBlock(true) // must set non-block, otherwise will block on read and lose fairness | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
v1 "github.com/refraction-networking/watm/tinygo/v1" | ||
v1net "github.com/refraction-networking/watm/tinygo/v1/net" | ||
) | ||
|
||
// type guard | ||
var _ v1.ListeningTransport = (*ReverseListeningTransport)(nil) | ||
|
||
type ReverseListeningTransport struct { | ||
listener v1net.Listener | ||
} | ||
|
||
func (lt *ReverseListeningTransport) SetListener(listener v1net.Listener) { | ||
lt.listener = listener | ||
} | ||
|
||
func (lt *ReverseListeningTransport) Accept() (v1net.Conn, error) { | ||
conn, err := lt.listener.Accept() // accept the connection | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ReverseConn{conn}, conn.SetNonBlock(true) // must set non-block, otherwise will block on read and lose fairness | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
v1net "github.com/refraction-networking/watm/tinygo/v1/net" | ||
) | ||
|
||
type ReverseConn struct { | ||
v1net.Conn // embedded Conn | ||
} | ||
|
||
func (rc *ReverseConn) Read(b []byte) (n int, err error) { | ||
tmpBuf := make([]byte, len(b)) | ||
n, err = rc.Conn.Read(tmpBuf) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
// reverse all bytes read successfully so far | ||
for i := 0; i < n; i++ { | ||
b[i] = tmpBuf[n-i-1] | ||
} | ||
|
||
return n, err | ||
} | ||
|
||
func (rc *ReverseConn) Write(b []byte) (n int, err error) { | ||
tmpBuf := make([]byte, len(b)) | ||
|
||
// reverse the bytes to be written | ||
for i := 0; i < len(b); i++ { | ||
tmpBuf[i] = b[len(b)-i-1] | ||
} | ||
|
||
return rc.Conn.Write(tmpBuf[:len(b)]) | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.