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

Merge branch 'master' of github.com:Psiphon-Labs/psiphon-tunnel-core into console-client-docker

Michael Goldberger 10 лет назад
Родитель
Сommit
31ff67854d

+ 1 - 1
psiphon/LookupIP.go

@@ -1,4 +1,4 @@
-// +build android linux
+// +build android linux darwin
 
 /*
  * Copyright (c) 2015, Psiphon Inc.

+ 1 - 1
psiphon/LookupIP_nobind.go

@@ -1,4 +1,4 @@
-// +build !android,!linux
+// +build !android,!linux,!darwin
 
 /*
  * Copyright (c) 2014, Psiphon Inc.

+ 1 - 1
psiphon/config.go

@@ -41,7 +41,7 @@ const (
 	TUNNEL_SSH_KEEP_ALIVE_PERIODIC_TIMEOUT         = 30 * time.Second
 	TUNNEL_SSH_KEEP_ALIVE_PERIODIC_INACTIVE_PERIOD = 10 * time.Second
 	TUNNEL_SSH_KEEP_ALIVE_PROBE_TIMEOUT            = 5 * time.Second
-	TUNNEL_SSH_KEEP_ALIVE_PROBE_INACTIVE_PERIOD    = 5 * time.Second
+	TUNNEL_SSH_KEEP_ALIVE_PROBE_INACTIVE_PERIOD    = 10 * time.Second
 	ESTABLISH_TUNNEL_TIMEOUT_SECONDS               = 300
 	ESTABLISH_TUNNEL_WORK_TIME                     = 60 * time.Second
 	ESTABLISH_TUNNEL_PAUSE_PERIOD                  = 5 * time.Second

+ 3 - 1
psiphon/transferstats/collector.go

@@ -150,12 +150,14 @@ func GetBytesTransferredForServer(serverID string) (sent, received int64) {
 }
 
 // GetForServer returns the json-able stats package for the given server.
-// If there are no stats, nil will be returned.
 func GetForServer(serverID string) (payload *serverStats) {
 	allStats.statsMutex.Lock()
 	defer allStats.statsMutex.Unlock()
 
 	payload = allStats.serverIDtoStats[serverID]
+	if payload == nil {
+		payload = newServerStats()
+	}
 	delete(allStats.serverIDtoStats, serverID)
 	return
 }

+ 9 - 8
psiphon/transferstats/transferstats_test.go

@@ -94,17 +94,16 @@ func (suite *StatsTestSuite) Test_StatsConn() {
 }
 
 func (suite *StatsTestSuite) Test_GetForServer() {
+
+	zeroPayload := newServerStats()
+
 	payload := GetForServer(_SERVER_ID)
-	suite.Nil(payload, "should get nil stats before any traffic (but not crash)")
+	suite.Equal(payload, zeroPayload, "should get zero stats before any traffic")
 
 	resp, err := suite.httpClient.Get("http://example.com/index.html")
 	suite.Nil(err, "need successful http to proceed with tests")
 	resp.Body.Close()
 
-	// Make sure there aren't stats returned for a bad server ID
-	payload = GetForServer("INVALID")
-	suite.Nil(payload, "should get nil stats for invalid server ID")
-
 	payload = GetForServer(_SERVER_ID)
 	suite.NotNil(payload, "should receive valid payload for valid server ID")
 
@@ -115,7 +114,7 @@ func (suite *StatsTestSuite) Test_GetForServer() {
 
 	// After we retrieve the stats for a server, they should be cleared out of the tracked stats
 	payload = GetForServer(_SERVER_ID)
-	suite.Nil(payload, "after retrieving stats for a server, there should be no more stats (until more data goes through)")
+	suite.Equal(payload, zeroPayload, "after retrieving stats for a server, there should be zero stats (until more data goes through)")
 }
 
 func (suite *StatsTestSuite) Test_PutBack() {
@@ -126,15 +125,17 @@ func (suite *StatsTestSuite) Test_PutBack() {
 	payloadToPutBack := GetForServer(_SERVER_ID)
 	suite.NotNil(payloadToPutBack, "should receive valid payload for valid server ID")
 
+	zeroPayload := newServerStats()
+
 	payload := GetForServer(_SERVER_ID)
-	suite.Nil(payload, "should not be any remaining stats after getting them")
+	suite.Equal(payload, zeroPayload, "should be zero stats after getting them")
 
 	PutBack(_SERVER_ID, payloadToPutBack)
 	// PutBack is asynchronous, so we'll need to wait a moment for it to do its thing
 	<-time.After(100 * time.Millisecond)
 
 	payload = GetForServer(_SERVER_ID)
-	suite.NotNil(payload, "stats should be re-added after putting back")
+	suite.NotEqual(payload, zeroPayload, "stats should be re-added after putting back")
 	suite.Equal(payload, payloadToPutBack, "stats should be the same as after the first retrieval")
 }
 

+ 7 - 6
psiphon/tunnel.go

@@ -532,6 +532,9 @@ func dialSsh(
 // resolve, while no new port forward is attempted which would otherwise
 // result in a tunnel failure detection.
 //
+// TODO: change "recently active" to include having received any
+// SSH protocol messages from the server, not just user payload?
+//
 func (tunnel *Tunnel) operateTunnel(config *Config, tunnelOwner TunnelOwner) {
 	defer tunnel.operateWaitGroup.Done()
 
@@ -717,11 +720,9 @@ func sendStats(tunnel *Tunnel) {
 	}
 
 	payload := transferstats.GetForServer(tunnel.serverEntry.IpAddress)
-	if payload != nil {
-		err := tunnel.session.DoStatusRequest(payload)
-		if err != nil {
-			NoticeAlert("DoStatusRequest failed for %s: %s", tunnel.serverEntry.IpAddress, err)
-			transferstats.PutBack(tunnel.serverEntry.IpAddress, payload)
-		}
+	err := tunnel.session.DoStatusRequest(payload)
+	if err != nil {
+		NoticeAlert("DoStatusRequest failed for %s: %s", tunnel.serverEntry.IpAddress, err)
+		transferstats.PutBack(tunnel.serverEntry.IpAddress, payload)
 	}
 }