improve client interface specificity and composability which eliminates much unnecessary code

This commit is contained in:
Serene Han 2016-06-13 11:05:26 -07:00
parent 02562ba750
commit 4ca0a3aa0a
6 changed files with 100 additions and 104 deletions

View file

@ -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",