Просмотр исходного кода

Merge remote-tracking branch 'upstream/master'

Adam Pritchard 11 лет назад
Родитель
Сommit
f5df7a700e
4 измененных файлов с 27 добавлено и 23 удалено
  1. 1 1
      AndroidLibrary/Dockerfile
  2. 12 0
      AndroidLibrary/make.bash
  3. 8 15
      psiphon/stats_collector.go
  4. 6 7
      psiphon/stats_test.go

+ 1 - 1
AndroidLibrary/Dockerfile

@@ -63,4 +63,4 @@ RUN echo "INSTALLING GO" && \
   ./all.bash && \
   ./all.bash && \
   CC_FOR_TARGET=$NDK_ROOT/bin/arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 ./make.bash
   CC_FOR_TARGET=$NDK_ROOT/bin/arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 ./make.bash
 
 
-WORKDIR $GOPATH/src/golang.org/x/mobile
+WORKDIR $GOPATH/src

+ 12 - 0
AndroidLibrary/make.bash

@@ -9,8 +9,20 @@ fi
 
 
 ANDROID_APP=$PWD
 ANDROID_APP=$PWD
 
 
+# Make sure we have our dependencies
+echo 'go-getting dependencies...'
+go get -d -v ./...
+
+# Force an update of the go-mobile package, since it's being improved rapidly
+# NOTE: for some reason this either doesn't complete or stalls for a very long time.
+#echo 'Updating go-mobile...'
+#go get -u -d -v golang.org/x/mobile/...
+
+echo 'Building library...'
 CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 \
 CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 \
   go build -a -v -ldflags="-shared" -o libgojni.so ./libpsi
   go build -a -v -ldflags="-shared" -o libgojni.so ./libpsi
 
 
 mkdir -p libs/armeabi-v7a
 mkdir -p libs/armeabi-v7a
 mv -f libgojni.so libs/armeabi-v7a/libgojni.so
 mv -f libgojni.so libs/armeabi-v7a/libgojni.so
+
+echo 'Library can be found at: libs/armeabi-v7a/libgojni.so'

+ 8 - 15
psiphon/stats_collector.go

@@ -36,7 +36,9 @@ import (
 
 
 // _CHANNEL_CAPACITY is the size of the channel that connections use to send stats
 // _CHANNEL_CAPACITY is the size of the channel that connections use to send stats
 // bundles to the collector/processor.
 // bundles to the collector/processor.
-var _CHANNEL_CAPACITY = 1000
+const (
+	_CHANNEL_CAPACITY = 1000
+)
 
 
 // Per-host/domain stats.
 // Per-host/domain stats.
 // Note that the bytes we're counting are the ones going into the tunnel, so do
 // Note that the bytes we're counting are the ones going into the tunnel, so do
@@ -105,24 +107,15 @@ type statsUpdate struct {
 	numBytesReceived int64
 	numBytesReceived int64
 }
 }
 
 
-// recordStats makes sure the given stats update is added to the global
-// collection. Guaranteed to not block.
+// recordStats adds the given stats update is added to the global collection.
 // Callers of this function should assume that it "takes control" of the
 // Callers of this function should assume that it "takes control" of the
 // statsUpdate object.
 // statsUpdate object.
 func recordStat(newStat *statsUpdate) {
 func recordStat(newStat *statsUpdate) {
+	// This function has the potential to block, if statsChan gets full. The
+	// intention is that we give statsChan a big enough buffer that it doesn't
+	// block in normal circumstances
 	statSlice := []*statsUpdate{newStat}
 	statSlice := []*statsUpdate{newStat}
-	// Priority: Don't block connections when updating stats. We can't just
-	// write to the statsChan, since that will block if it's full. We could
-	// launch a goroutine for each update, but that seems like  unnecessary
-	// overhead. So we'll try to write to the channel, and launch a goro if it
-	// fails.
-	select {
-	case allStats.statsChan <- statSlice:
-	default:
-		go func() {
-			allStats.statsChan <- statSlice
-		}()
-	}
+	allStats.statsChan <- statSlice
 }
 }
 
 
 // processStats is a goro started by Start() and runs until Stop(). It collects
 // processStats is a goro started by Start() and runs until Stop(). It collects

+ 6 - 7
psiphon/stats_test.go

@@ -32,7 +32,9 @@ import (
 	"github.com/stretchr/testify/suite"
 	"github.com/stretchr/testify/suite"
 )
 )
 
 
-var _SERVER_ID = "myserverid"
+const (
+	_SERVER_ID = "myserverid"
+)
 
 
 type StatsTestSuite struct {
 type StatsTestSuite struct {
 	suite.Suite
 	suite.Suite
@@ -252,16 +254,13 @@ func (suite *StatsTestSuite) Test_Regex() {
 
 
 func (suite *StatsTestSuite) Test_recordStat() {
 func (suite *StatsTestSuite) Test_recordStat() {
 	// The normal operation of this function will get exercised during the
 	// The normal operation of this function will get exercised during the
-	// other tests, but there is a code branch that only gets hit when the
-	// allStats.statsChan is filled. To make sure we fill the channel, we will
-	// lock the stats access mutex, try to record a bunch of stats, and then
-	// release it.
-	allStats.statsMutex.Lock()
+	// other tests. Here we will quickly record more stats updates than the
+	// channel capacity. The test is just that this function returns, and doesn't
+	// crash or block forever.
 	stat := statsUpdate{"test", "test", 1, 1}
 	stat := statsUpdate{"test", "test", 1, 1}
 	for i := 0; i < _CHANNEL_CAPACITY*2; i++ {
 	for i := 0; i < _CHANNEL_CAPACITY*2; i++ {
 		recordStat(&stat)
 		recordStat(&stat)
 	}
 	}
-	allStats.statsMutex.Unlock()
 }
 }
 
 
 func (suite *StatsTestSuite) Test_getTLSHostname() {
 func (suite *StatsTestSuite) Test_getTLSHostname() {