Sfoglia il codice sorgente

Remove legacy redis support

Rod Hynes 9 anni fa
parent
commit
c4f6e54566

+ 0 - 14
psiphon/server/config.go

@@ -54,9 +54,6 @@ const (
 	SSH_TCP_PORT_FORWARD_DIAL_TIMEOUT     = 30 * time.Second
 	SSH_TCP_PORT_FORWARD_COPY_BUFFER_SIZE = 8192
 	SSH_OBFUSCATED_KEY_BYTE_LENGTH        = 32
-	REDIS_POOL_MAX_IDLE                   = 50
-	REDIS_POOL_MAX_ACTIVE                 = 1000
-	REDIS_POOL_IDLE_TIMEOUT               = 5 * time.Minute
 	GEOIP_SESSION_CACHE_TTL               = 60 * time.Minute
 )
 
@@ -102,10 +99,6 @@ type Config struct {
 	// performed.
 	GeoIPDatabaseFilename string
 
-	// RedisServerAddress is the TCP address of a redis server. When
-	// set, redis is used to store per-session GeoIP information.
-	RedisServerAddress string
-
 	// PsinetDatabaseFilename is the path of the Psiphon automation
 	// jsonpickle format Psiphon API data file.
 	PsinetDatabaseFilename string
@@ -316,12 +309,6 @@ func (config *Config) RunLoadMonitor() bool {
 	return config.LoadMonitorPeriodSeconds > 0
 }
 
-// UseRedis indicates whether to store per-session GeoIP information in
-// redis. This is for integration with the legacy psi_web component.
-func (config *Config) UseRedis() bool {
-	return config.RedisServerAddress != ""
-}
-
 // UseFail2Ban indicates whether to log client IP addresses, in authentication
 // failure cases, to the local syslog service AUTH facility for use by fail2ban.
 func (config *Config) UseFail2Ban() bool {
@@ -612,7 +599,6 @@ func GenerateConfig(params *GenerateConfigParams) ([]byte, []byte, error) {
 		SSHPassword:                    sshPassword,
 		ObfuscatedSSHKey:               obfuscatedSSHKey,
 		TunnelProtocolPorts:            params.TunnelProtocolPorts,
-		RedisServerAddress:             "",
 		UDPForwardDNSServerAddress:     "8.8.8.8:53",
 		UDPInterceptUdpgwServerAddress: "127.0.0.1:7300",
 		MeekCookieEncryptionPrivateKey: meekCookieEncryptionPrivateKey,

+ 0 - 116
psiphon/server/redis.go

@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2016, Psiphon Inc.
- * All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package server
-
-import (
-	"encoding/json"
-
-	"github.com/Psiphon-Inc/redigo/redis"
-	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon"
-)
-
-// UpdateRedisForLegacyPsiWeb sets the Psiphon session and discovery records for
-// a new SSH connection following the conventions of the legacy psi_web component.
-// This facility is used so psi_web can use the GeoIP values the SSH server has
-// resolved for the user connection.
-// The redis database indexes, expiry values, and record schemas all match the
-// legacy psi_web configuration.
-func UpdateRedisForLegacyPsiWeb(psiphonSessionID string, geoIPData GeoIPData) error {
-
-	redisSessionDBIndex := 0
-
-	//  Discard sessions older than 60 minutes
-	sessionExpireSeconds := 60 * 60
-
-	sessionRecord, err := json.Marshal(
-		struct {
-			Country string `json:"region"`
-			City    string `json:"city"`
-			ISP     string `json:"isp"`
-		}{geoIPData.Country, geoIPData.City, geoIPData.ISP})
-	if err != nil {
-		return psiphon.ContextError(err)
-	}
-
-	redisDiscoveryDBIndex := 1
-
-	// Discard discovery records older than 5 minutes
-	discoveryExpireSeconds := 60 * 5
-
-	discoveryRecord, err := json.Marshal(
-		struct {
-			DiscoveryValue int `json:"client_ip_address_strategy_value"`
-		}{geoIPData.DiscoveryValue})
-	if err != nil {
-		return psiphon.ContextError(err)
-	}
-
-	conn := redisPool.Get()
-	defer conn.Close()
-
-	// Note: using SET with NX (set if not exists) so as to not clobber
-	// any existing records set by an upstream connection server (i.e.,
-	// meek server). We allow expiry deadline extension unconditionally.
-
-	conn.Send("MULTI")
-
-	conn.Send("SELECT", redisSessionDBIndex)
-	// http://redis.io/commands/set -- NX/EX options require Redis 2.6.12
-	//conn.Send("SET", psiphonSessionID, string(sessionRecord), "NX", "EX", sessionExpireSeconds)
-	conn.Send("SETNX", psiphonSessionID, string(sessionRecord))
-	conn.Send("EXPIRE", psiphonSessionID, sessionExpireSeconds)
-
-	conn.Send("SELECT", redisDiscoveryDBIndex)
-	//conn.Send("SET", psiphonSessionID, string(discoveryRecord), "NX", "EX", discoveryExpireSeconds)
-	conn.Send("SETNX", psiphonSessionID, string(discoveryRecord))
-	conn.Send("EXPIRE", psiphonSessionID, discoveryExpireSeconds)
-
-	_, err = conn.Do("EXEC")
-	if err != nil {
-		return psiphon.ContextError(err)
-	}
-
-	return nil
-}
-
-var redisPool *redis.Pool
-
-// InitRedis establishes a redis client connection pool and
-// also tests at least one single connection.
-func InitRedis(config *Config) error {
-	redisPool = &redis.Pool{
-		Dial: func() (redis.Conn, error) {
-			return redis.Dial("tcp", config.RedisServerAddress)
-		},
-		MaxIdle:     REDIS_POOL_MAX_IDLE,
-		MaxActive:   REDIS_POOL_MAX_ACTIVE,
-		Wait:        false,
-		IdleTimeout: REDIS_POOL_IDLE_TIMEOUT,
-	}
-
-	// Exercise a connection to the configured redis server so
-	// that Init fails if the configuration is incorrect or the
-	// server is not responding.
-	conn := redisPool.Get()
-	_, err := conn.Do("PING")
-	conn.Close()
-
-	return err
-}

+ 3 - 12
psiphon/server/services.go

@@ -34,10 +34,9 @@ import (
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon"
 )
 
-// RunServices initializes support functions including logging, GeoIP service, and
-// redis connection pooling; and then starts the server components and runs them
-// until os.Interrupt or os.Kill signals are received. The config determines
-// which components are run.
+// RunServices initializes support functions including logging and GeoIP services;
+// and then starts the server components and runs them until os.Interrupt or
+// os.Kill signals are received. The config determines which components are run.
 func RunServices(encodedConfigs [][]byte) error {
 
 	config, err := LoadConfig(encodedConfigs)
@@ -58,14 +57,6 @@ func RunServices(encodedConfigs [][]byte) error {
 		return psiphon.ContextError(err)
 	}
 
-	if config.UseRedis() {
-		err = InitRedis(config)
-		if err != nil {
-			log.WithContextFields(LogFields{"error": err}).Error("init redis failed")
-			return psiphon.ContextError(err)
-		}
-	}
-
 	psinetDatabase, err := NewPsinetDatabase(config.PsinetDatabaseFilename)
 	if err != nil {
 		log.WithContextFields(LogFields{"error": err}).Error("init PsinetDatabase failed")

+ 0 - 10
psiphon/server/tunnelServer.go

@@ -547,16 +547,6 @@ func (sshClient *sshClient) passwordCallback(conn ssh.ConnMetadata, password []b
 	// available to the web server for web transport Psiphon API requests.
 	SetGeoIPSessionCache(psiphonSessionID, geoIPData)
 
-	if sshClient.sshServer.config.UseRedis() {
-		err = UpdateRedisForLegacyPsiWeb(psiphonSessionID, geoIPData)
-		if err != nil {
-			log.WithContextFields(LogFields{
-				"psiphonSessionID": psiphonSessionID,
-				"error":            err}).Warning("UpdateRedisForLegacyPsiWeb failed")
-			// Allow the connection to proceed; legacy psi_web will not get accurate GeoIP values.
-		}
-	}
-
 	return nil, nil
 }