Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tapdance/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,7 @@ func (a *assets) saveClientConf() error {
func (a *assets) SetStatsSocksAddr(addr string) {
a.socksAddr = addr
}

func (a *assets) GetStatsSocksAddr() string {
return a.socksAddr
}
10 changes: 7 additions & 3 deletions tapdance/conjure.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ func DialConjure(ctx context.Context, cjSession *ConjureSession) (net.Conn, erro
Logger().Debugf("%v Successfully sent registrations, sleeping for: %v ms", cjSession.IDString(), toSleep)
time.Sleep(toSleep)

Logger().Debugf("%v Woke from sleep, attempting to Connect ...", cjSession.IDString())
return registration.Connect(ctx)
// return Connect(cjSession)
Logger().Tracef("%v Woke from sleep, attempting to Connect ...", cjSession.IDString())

conn, err := registration.Connect(ctx)
if conn != nil && err == nil {
StatsReporting(cjSession.stats)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a go routine as this will block the return of con to the user by a full tcp (tls) session

}
return conn, err
}

// Register - Send registrations equal to the width specified in the Conjure Session
Expand Down
38 changes: 38 additions & 0 deletions tapdance/logger.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package tapdance

import (
"bytes"
"fmt"
"net/http"
"net/url"
"sync"

"github.com/golang/protobuf/proto"
pb "github.com/refraction-networking/gotapdance/protobuf"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -35,3 +40,36 @@ func Logger() *logrus.Logger {
})
return logrusLogger
}

func StatsReporting(stats *pb.SessionStats) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of TODOs and commented out lines of code in this function.
Do we need all of them, or can we remove some?

socks_url, err := url.Parse("socks5://" + Assets().GetStatsSocksAddr())
// Test socks5 proxy
//socks_url, err := url.Parse("socks5://localhost:8080")
fmt.Printf("Got %v as socks5 proxy\n", socks_url)
if err != nil {
// TODO this should be logged, not printed
fmt.Printf("Could not parse socks addr %v\n", Assets().GetStatsSocksAddr())
return
}
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(socks_url)}}

data, err := proto.Marshal(stats)
if err != nil {
// TODO this should be logged, not printed
fmt.Println("Could not marshal stats protobuf")
return
}

// TODO send stats protobuf to some refraction.network endpoint
client.Post("https://nzimm.net", "stats", bytes.NewReader(data))
return

/*
resp, _ := client.Post("https://nzimm.net", "stats", bytes.NewReader(data))
if err != nil {
// TODO this should be logged, not printed
fmt.Println("Could not parse socks addr %v", Assets().GetStatsSocksAddr())
return
}
*/
}
17 changes: 17 additions & 0 deletions tapdance/logger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tapdance

import (
"testing"

pb "github.com/refraction-networking/gotapdance/protobuf"
)

func TestStatsReporting(t *testing.T) {
reg := ConjureReg{}
testRTT := uint32(1000)
reg.stats = &pb.SessionStats{
TotalTimeToConnect: &testRTT,
TcpToDecoy: &testRTT,
}
StatsReporting(reg.stats)
}