commit 624750d5a8a0b0acedd495168bcb2b5fc627fcb8 Author: Cecylia Bocovich cohosh@torproject.org Date: Thu Sep 9 11:34:07 2021 -0400
Stop exporting code that should be internal --- client/lib/interfaces.go | 11 ----------- client/lib/peers.go | 4 ++-- client/lib/rendezvous.go | 16 ++++++++-------- client/lib/snowflake.go | 9 ++++----- client/lib/turbotunnel.go | 22 +++++++++++----------- client/lib/util.go | 30 +++++++++++++++--------------- client/lib/webrtc.go | 8 ++++---- 7 files changed, 44 insertions(+), 56 deletions(-)
diff --git a/client/lib/interfaces.go b/client/lib/interfaces.go index 5378f4a..0a871b8 100644 --- a/client/lib/interfaces.go +++ b/client/lib/interfaces.go @@ -1,9 +1,5 @@ package lib
-import ( - "net" -) - // Interface for catching Snowflakes. (aka the remote dialer) type Tongue interface { Catch() (*WebRTCPeer, error) @@ -25,10 +21,3 @@ type SnowflakeCollector interface { // Signal when the collector has stopped collecting. Melted() <-chan struct{} } - -// Interface to adapt to goptlib's SocksConn struct. -type SocksConnector interface { - Grant(*net.TCPAddr) error - Reject() error - net.Conn -} diff --git a/client/lib/peers.go b/client/lib/peers.go index 7fba572..1abcd95 100644 --- a/client/lib/peers.go +++ b/client/lib/peers.go @@ -21,7 +21,7 @@ import ( // version of Snowflake) type Peers struct { Tongue - BytesLogger BytesLogger + bytesLogger bytesLogger
snowflakeChan chan *WebRTCPeer activePeers *list.List @@ -88,7 +88,7 @@ func (p *Peers) Pop() *WebRTCPeer { continue } // Set to use the same rate-limited traffic logger to keep consistency. - snowflake.BytesLogger = p.BytesLogger + snowflake.bytesLogger = p.bytesLogger return snowflake } } diff --git a/client/lib/rendezvous.go b/client/lib/rendezvous.go index 8af638f..d58e729 100644 --- a/client/lib/rendezvous.go +++ b/client/lib/rendezvous.go @@ -42,14 +42,14 @@ type rendezvousMethod interface { type BrokerChannel struct { rendezvous rendezvousMethod keepLocalAddresses bool - NATType string + natType string lock sync.Mutex }
// We make a copy of DefaultTransport because we want the default Dial // and TLSHandshakeTimeout settings. But we want to disable the default // ProxyFromEnvironment setting. -func CreateBrokerTransport() http.RoundTripper { +func createBrokerTransport() http.RoundTripper { transport := http.DefaultTransport.(*http.Transport) transport.Proxy = nil transport.ResponseHeaderTimeout = 15 * time.Second @@ -59,7 +59,7 @@ func CreateBrokerTransport() http.RoundTripper { // Construct a new BrokerChannel, where: // |broker| is the full URL of the facilitating program which assigns proxies // to clients, and |front| is the option fronting domain. -func NewBrokerChannel(broker, ampCache, front string, transport http.RoundTripper, keepLocalAddresses bool) (*BrokerChannel, error) { +func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (*BrokerChannel, error) { log.Println("Rendezvous using Broker at:", broker) if ampCache != "" { log.Println("Through AMP cache at:", ampCache) @@ -71,9 +71,9 @@ func NewBrokerChannel(broker, ampCache, front string, transport http.RoundTrippe var rendezvous rendezvousMethod var err error if ampCache != "" { - rendezvous, err = newAMPCacheRendezvous(broker, ampCache, front, transport) + rendezvous, err = newAMPCacheRendezvous(broker, ampCache, front, createBrokerTransport()) } else { - rendezvous, err = newHTTPRendezvous(broker, front, transport) + rendezvous, err = newHTTPRendezvous(broker, front, createBrokerTransport()) } if err != nil { return nil, err @@ -82,7 +82,7 @@ func NewBrokerChannel(broker, ampCache, front string, transport http.RoundTrippe return &BrokerChannel{ rendezvous: rendezvous, keepLocalAddresses: keepLocalAddresses, - NATType: nat.NATUnknown, + natType: nat.NATUnknown, }, nil }
@@ -110,7 +110,7 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) ( bc.lock.Lock() req := &messages.ClientPollRequest{ Offer: offerSDP, - NAT: bc.NATType, + NAT: bc.natType, } encReq, err := req.EncodePollRequest() bc.lock.Unlock() @@ -138,7 +138,7 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
func (bc *BrokerChannel) SetNATType(NATType string) { bc.lock.Lock() - bc.NATType = NATType + bc.natType = NATType bc.lock.Unlock() log.Printf("NAT Type: %s", NATType) } diff --git a/client/lib/snowflake.go b/client/lib/snowflake.go index 8b01d88..fb7fab9 100644 --- a/client/lib/snowflake.go +++ b/client/lib/snowflake.go @@ -71,8 +71,7 @@ func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
// Rendezvous with broker using the given parameters. broker, err := NewBrokerChannel( - config.BrokerURL, config.AmpCacheURL, config.FrontDomain, CreateBrokerTransport(), - config.KeepLocalAddresses) + config.BrokerURL, config.AmpCacheURL, config.FrontDomain, config.KeepLocalAddresses) if err != nil { return nil, err } @@ -103,7 +102,7 @@ func (t *Transport) Dial() (net.Conn, error) { cleanup = append(cleanup, func() { snowflakes.End() })
// Use a real logger to periodically output how much traffic is happening. - snowflakes.BytesLogger = NewBytesSyncLogger() + snowflakes.bytesLogger = newBytesSyncLogger()
log.Printf("---- SnowflakeConn: begin collecting snowflakes ---") go connectLoop(snowflakes) @@ -198,7 +197,7 @@ func newSession(snowflakes SnowflakeCollector) (net.PacketConn, *smux.Session, e // We build a persistent KCP session on a sequence of ephemeral WebRTC // connections. This dialContext tells RedialPacketConn how to get a new // WebRTC connection when the previous one dies. Inside each WebRTC - // connection, we use EncapsulationPacketConn to encode packets into a + // connection, we use encapsulationPacketConn to encode packets into a // stream. dialContext := func(ctx context.Context) (net.PacketConn, error) { log.Printf("redialing on same connection") @@ -218,7 +217,7 @@ func newSession(snowflakes SnowflakeCollector) (net.PacketConn, *smux.Session, e if err != nil { return nil, err } - return NewEncapsulationPacketConn(dummyAddr{}, dummyAddr{}, conn), nil + return newEncapsulationPacketConn(dummyAddr{}, dummyAddr{}, conn), nil } pconn := turbotunnel.NewRedialPacketConn(dummyAddr{}, dummyAddr{}, dialContext)
diff --git a/client/lib/turbotunnel.go b/client/lib/turbotunnel.go index aad2e6a..49a011c 100644 --- a/client/lib/turbotunnel.go +++ b/client/lib/turbotunnel.go @@ -12,10 +12,10 @@ import (
var errNotImplemented = errors.New("not implemented")
-// EncapsulationPacketConn implements the net.PacketConn interface over an +// encapsulationPacketConn implements the net.PacketConn interface over an // io.ReadWriteCloser stream, using the encapsulation package to represent // packets in a stream. -type EncapsulationPacketConn struct { +type encapsulationPacketConn struct { io.ReadWriteCloser localAddr net.Addr remoteAddr net.Addr @@ -23,11 +23,11 @@ type EncapsulationPacketConn struct { }
// NewEncapsulationPacketConn makes -func NewEncapsulationPacketConn( +func newEncapsulationPacketConn( localAddr, remoteAddr net.Addr, conn io.ReadWriteCloser, -) *EncapsulationPacketConn { - return &EncapsulationPacketConn{ +) *encapsulationPacketConn { + return &encapsulationPacketConn{ ReadWriteCloser: conn, localAddr: localAddr, remoteAddr: remoteAddr, @@ -36,7 +36,7 @@ func NewEncapsulationPacketConn( }
// ReadFrom reads an encapsulated packet from the stream. -func (c *EncapsulationPacketConn) ReadFrom(p []byte) (int, net.Addr, error) { +func (c *encapsulationPacketConn) ReadFrom(p []byte) (int, net.Addr, error) { data, err := encapsulation.ReadData(c.ReadWriteCloser) if err != nil { return 0, c.remoteAddr, err @@ -45,7 +45,7 @@ func (c *EncapsulationPacketConn) ReadFrom(p []byte) (int, net.Addr, error) { }
// WriteTo writes an encapsulated packet to the stream. -func (c *EncapsulationPacketConn) WriteTo(p []byte, addr net.Addr) (int, error) { +func (c *encapsulationPacketConn) WriteTo(p []byte, addr net.Addr) (int, error) { // addr is ignored. _, err := encapsulation.WriteData(c.bw, p) if err == nil { @@ -59,10 +59,10 @@ func (c *EncapsulationPacketConn) WriteTo(p []byte, addr net.Addr) (int, error)
// LocalAddr returns the localAddr value that was passed to // NewEncapsulationPacketConn. -func (c *EncapsulationPacketConn) LocalAddr() net.Addr { +func (c *encapsulationPacketConn) LocalAddr() net.Addr { return c.localAddr }
-func (c *EncapsulationPacketConn) SetDeadline(t time.Time) error { return errNotImplemented } -func (c *EncapsulationPacketConn) SetReadDeadline(t time.Time) error { return errNotImplemented } -func (c *EncapsulationPacketConn) SetWriteDeadline(t time.Time) error { return errNotImplemented } +func (c *encapsulationPacketConn) SetDeadline(t time.Time) error { return errNotImplemented } +func (c *encapsulationPacketConn) SetReadDeadline(t time.Time) error { return errNotImplemented } +func (c *encapsulationPacketConn) SetWriteDeadline(t time.Time) error { return errNotImplemented } diff --git a/client/lib/util.go b/client/lib/util.go index 0eb8ddd..00b3709 100644 --- a/client/lib/util.go +++ b/client/lib/util.go @@ -9,27 +9,27 @@ const ( LogTimeInterval = 5 * time.Second )
-type BytesLogger interface { - AddOutbound(int) - AddInbound(int) +type bytesLogger interface { + addOutbound(int) + addInbound(int) }
-// Default BytesLogger does nothing. -type BytesNullLogger struct{} +// Default bytesLogger does nothing. +type bytesNullLogger struct{}
-func (b BytesNullLogger) AddOutbound(amount int) {} -func (b BytesNullLogger) AddInbound(amount int) {} +func (b bytesNullLogger) addOutbound(amount int) {} +func (b bytesNullLogger) addInbound(amount int) {}
-// BytesSyncLogger uses channels to safely log from multiple sources with output +// bytesSyncLogger uses channels to safely log from multiple sources with output // occuring at reasonable intervals. -type BytesSyncLogger struct { +type bytesSyncLogger struct { outboundChan chan int inboundChan chan int }
-// NewBytesSyncLogger returns a new BytesSyncLogger and starts it loggin. -func NewBytesSyncLogger() *BytesSyncLogger { - b := &BytesSyncLogger{ +// newBytesSyncLogger returns a new bytesSyncLogger and starts it loggin. +func newBytesSyncLogger() *bytesSyncLogger { + b := &bytesSyncLogger{ outboundChan: make(chan int, 5), inboundChan: make(chan int, 5), } @@ -37,7 +37,7 @@ func NewBytesSyncLogger() *BytesSyncLogger { return b }
-func (b *BytesSyncLogger) log() { +func (b *bytesSyncLogger) log() { var outbound, inbound, outEvents, inEvents int ticker := time.NewTicker(LogTimeInterval) for { @@ -61,10 +61,10 @@ func (b *BytesSyncLogger) log() { } }
-func (b *BytesSyncLogger) AddOutbound(amount int) { +func (b *bytesSyncLogger) addOutbound(amount int) { b.outboundChan <- amount }
-func (b *BytesSyncLogger) AddInbound(amount int) { +func (b *bytesSyncLogger) addInbound(amount int) { b.inboundChan <- amount } diff --git a/client/lib/webrtc.go b/client/lib/webrtc.go index 2f931ac..6fc24c0 100644 --- a/client/lib/webrtc.go +++ b/client/lib/webrtc.go @@ -32,7 +32,7 @@ type WebRTCPeer struct {
once sync.Once // Synchronization for PeerConnection destruction
- BytesLogger BytesLogger + bytesLogger bytesLogger }
// Construct a WebRTC PeerConnection. @@ -49,7 +49,7 @@ func NewWebRTCPeer(config *webrtc.Configuration, connection.closed = make(chan struct{})
// Override with something that's not NullLogger to have real logging. - connection.BytesLogger = &BytesNullLogger{} + connection.bytesLogger = &bytesNullLogger{}
// Pipes remain the same even when DataChannel gets switched. connection.recvPipe, connection.writePipe = io.Pipe() @@ -75,7 +75,7 @@ func (c *WebRTCPeer) Write(b []byte) (int, error) { if err != nil { return 0, err } - c.BytesLogger.AddOutbound(len(b)) + c.bytesLogger.addOutbound(len(b)) return len(b), nil }
@@ -186,7 +186,7 @@ func (c *WebRTCPeer) preparePeerConnection(config *webrtc.Configuration) error { log.Println("0 length message---") } n, err := c.writePipe.Write(msg.Data) - c.BytesLogger.AddInbound(n) + c.bytesLogger.addInbound(n) if err != nil { // TODO: Maybe shouldn't actually close. log.Println("Error writing to SOCKS pipe")
tor-commits@lists.torproject.org