mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Use gorilla websocket in proxy-go too
Trac: 32465
This commit is contained in:
parent
7557e96a8d
commit
30b5ef8a9e
5 changed files with 128 additions and 134 deletions
|
@ -374,23 +374,4 @@ func TestUtilityFuncs(t *testing.T) {
|
|||
sid2 := genSessionID()
|
||||
So(sid1, ShouldNotEqual, sid2)
|
||||
})
|
||||
Convey("CopyLoop", t, func() {
|
||||
c1, s1 := net.Pipe()
|
||||
c2, s2 := net.Pipe()
|
||||
go CopyLoop(s1, s2)
|
||||
go func() {
|
||||
bytes := []byte("Hello!")
|
||||
c1.Write(bytes)
|
||||
}()
|
||||
bytes := make([]byte, 6)
|
||||
n, err := c2.Read(bytes)
|
||||
So(n, ShouldEqual, 6)
|
||||
So(err, ShouldEqual, nil)
|
||||
So(bytes, ShouldResemble, []byte("Hello!"))
|
||||
s1.Close()
|
||||
|
||||
//Check that copy loop has closed other connection
|
||||
_, err = s2.Write(bytes)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -21,8 +21,9 @@ import (
|
|||
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/common/messages"
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/common/safelog"
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/common/websocketconn"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/pion/webrtc"
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
const defaultBrokerURL = "https://snowflake-broker.bamsoftware.com/"
|
||||
|
@ -239,22 +240,6 @@ func (b *Broker) sendAnswer(sid string, pc *webrtc.PeerConnection) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func CopyLoop(c1 net.Conn, c2 net.Conn) {
|
||||
var wg sync.WaitGroup
|
||||
copyer := func(dst io.ReadWriteCloser, src io.ReadWriteCloser) {
|
||||
defer wg.Done()
|
||||
if _, err := io.Copy(dst, src); err != nil {
|
||||
log.Printf("io.Copy inside CopyLoop generated an error: %v", err)
|
||||
}
|
||||
dst.Close()
|
||||
src.Close()
|
||||
}
|
||||
wg.Add(2)
|
||||
go copyer(c1, c2)
|
||||
go copyer(c2, c1)
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// We pass conn.RemoteAddr() as an additional parameter, rather than calling
|
||||
// conn.RemoteAddr() inside this function, as a workaround for a hang that
|
||||
// otherwise occurs inside of conn.pc.RemoteDescription() (called by
|
||||
|
@ -279,15 +264,15 @@ func datachannelHandler(conn *webRTCConn, remoteAddr net.Addr) {
|
|||
log.Printf("no remote address given in websocket")
|
||||
}
|
||||
|
||||
wsConn, err := websocket.Dial(u.String(), "", relayURL)
|
||||
ws, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
log.Printf("error dialing relay: %s", err)
|
||||
return
|
||||
}
|
||||
wsConn := websocketconn.NewWebSocketConn(ws)
|
||||
log.Printf("connected to relay")
|
||||
defer wsConn.Close()
|
||||
wsConn.PayloadType = websocket.BinaryFrame
|
||||
CopyLoop(conn, wsConn)
|
||||
websocketconn.CopyLoop(conn, &wsConn)
|
||||
log.Printf("datachannelHandler ends")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue