Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats reporting #33

Open
wants to merge 3 commits into
base: conjure
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 {
go 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.

This is on me, but both cjSession, and registration track stats and I'm not sure exactly which of the stats we want to send via this channel. I think we probably want registration.stats. This is mostly an issue of deciding exactly what we want to track and send over this channel.

It may be worth opening a different issue to deal with this, as this change does complete the task of setting up the channel to communicate stats which is the issue that we opened here.

thoughts @nzimm?

Copy link
Author

Choose a reason for hiding this comment

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

I think reporting the correct stats protobuf probably falls under the scope of this ticket.
I'm just not sure what is tracked differently between cjSession.stats and registration.stats

}
return conn, err
}

// Register - Send registrations equal to the width specified in the Conjure Session
Expand Down
27 changes: 27 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,25 @@ 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 {
Logger().Debugf("Could not parse socks addr %v: %v\n", Assets().GetStatsSocksAddr(), err)
return
}
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(socks_url)}}

data, err := proto.Marshal(stats)
if err != nil {
Logger().Debugf("Could not marshal stats protobuf: %v", err)
return
}

// TODO setup stats endpoint
client.Post("https://stats.refraction.network", "stats", bytes.NewReader(data))
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)
}