Browse Source

remove ip-based caching so that it's possible to reliably generate new urls

Alan Shreve 12 years ago
parent
commit
f2009d7f52
1 changed files with 4 additions and 15 deletions
  1. 4 15
      src/ngrok/server/registry.go

+ 4 - 15
src/ngrok/server/registry.go

@@ -3,7 +3,6 @@ package server
 import (
 	"encoding/gob"
 	"fmt"
-	"net"
 	"ngrok/cache"
 	"ngrok/log"
 	"sync"
@@ -90,26 +89,18 @@ func (r *TunnelRegistry) Register(url string, t *Tunnel) error {
 	return nil
 }
 
-func (r *TunnelRegistry) cacheKeys(t *Tunnel) (ip string, id string) {
-	clientIp := t.ctl.conn.RemoteAddr().(*net.TCPAddr).IP.String()
-	clientId := t.ctl.id
-
-	ipKey := fmt.Sprintf("client-ip-%s:%s", t.req.Protocol, clientIp)
-	idKey := fmt.Sprintf("client-id-%s:%s", t.req.Protocol, clientId)
-	return ipKey, idKey
+func (r *TunnelRegistry) cacheKeys(t *Tunnel) (string) {
+	return fmt.Sprintf("client-id-%s:%s", t.req.Protocol, t.ctl.id)
 }
 
 func (r *TunnelRegistry) GetCachedRegistration(t *Tunnel) (url string) {
-	ipCacheKey, idCacheKey := r.cacheKeys(t)
+	idCacheKey := r.cacheKeys(t)
 
 	// check cache for ID first, because we prefer that over IP which might
 	// not be specific to a user because of NATs
 	if v, ok := r.affinity.Get(idCacheKey); ok {
 		url = string(v.(cacheUrl))
 		t.Debug("Found registry affinity %s for %s", url, idCacheKey)
-	} else if v, ok := r.affinity.Get(ipCacheKey); ok {
-		url = string(v.(cacheUrl))
-		t.Debug("Found registry affinity %s for %s", url, ipCacheKey)
 	}
 	return
 }
@@ -117,12 +108,10 @@ func (r *TunnelRegistry) GetCachedRegistration(t *Tunnel) (url string) {
 func (r *TunnelRegistry) RegisterAndCache(url string, t *Tunnel) (err error) {
 	if err = r.Register(url, t); err == nil {
 		// we successfully assigned a url, cache it
-		ipCacheKey, idCacheKey := r.cacheKeys(t)
-		r.affinity.Set(ipCacheKey, cacheUrl(url))
+		idCacheKey := r.cacheKeys(t)
 		r.affinity.Set(idCacheKey, cacheUrl(url))
 	}
 	return
-
 }
 
 // Register a tunnel with the following process: