mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
improve client interface specificity and composability which eliminates much unnecessary code
This commit is contained in:
parent
02562ba750
commit
4ca0a3aa0a
6 changed files with 100 additions and 104 deletions
|
@ -26,21 +26,6 @@ const (
|
|||
// ends, -1 is written.
|
||||
var handlerChan = make(chan int)
|
||||
|
||||
func copyLoop(a, b net.Conn) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
io.Copy(b, a)
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
io.Copy(a, b)
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Wait()
|
||||
log.Println("copy loop ended")
|
||||
}
|
||||
|
||||
// Maintain |SnowflakeCapacity| number of available WebRTC connections, to
|
||||
// transfer to the Tor SOCKS handler when needed.
|
||||
func ConnectLoop(snowflakes SnowflakeCollector) {
|
||||
|
@ -104,11 +89,28 @@ func handler(socks SocksConnector, snowflakes SnowflakeCollector) error {
|
|||
|
||||
// When WebRTC resets, close the SOCKS connection, which induces new handler.
|
||||
// TODO: Double check this / fix it.
|
||||
<-snowflake.reset
|
||||
snowflake.WaitForReset()
|
||||
log.Println("---- Closed ---")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Exchanges bytes between two ReadWriters.
|
||||
// (In this case, between a SOCKS and WebRTC connection.)
|
||||
func copyLoop(a, b io.ReadWriter) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
io.Copy(b, a)
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
io.Copy(a, b)
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Wait()
|
||||
log.Println("copy loop ended")
|
||||
}
|
||||
|
||||
func main() {
|
||||
webrtc.SetLoggingVerbosity(1)
|
||||
logFile, err := os.OpenFile("snowflake.log",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue