diff --git a/app/app.go b/app/app.go index 831ff1a..7a7486e 100644 --- a/app/app.go +++ b/app/app.go @@ -18,7 +18,7 @@ import ( type application struct { peers map[string]peer.CwtchPeer - mn connectivity.ACN + acn connectivity.ACN directory string mutex sync.Mutex primaryonion string @@ -42,9 +42,9 @@ type Application interface { } // NewApp creates a new app with some environment awareness and initializes a Tor Manager -func NewApp(mn connectivity.ACN, appDirectory string) Application { +func NewApp(acn connectivity.ACN, appDirectory string) Application { log.Printf("NewApp(%v)\n", appDirectory) - app := &application{peers: make(map[string]peer.CwtchPeer), storage: make(map[string]storage.ProfileStore), directory: appDirectory, mn: mn} + app := &application{peers: make(map[string]peer.CwtchPeer), storage: make(map[string]storage.ProfileStore), directory: appDirectory, acn: acn} os.Mkdir(path.Join(app.directory, "profiles"), 0700) return app } @@ -73,7 +73,7 @@ func (app *application) CreatePeer(name string, password string) (peer.CwtchPeer if err != nil { return nil, err } - p.Init(app.mn) + p.Init(app.acn) p.Listen() _, exists := app.peers[p.GetProfile().Onion] if exists { @@ -110,7 +110,7 @@ func (app *application) LoadProfiles(password string) error { continue } - p.Init(app.mn) + p.Init(app.acn) p.Listen() app.mutex.Lock() diff --git a/app/cli/main.go b/app/cli/main.go index 8b693c0..ecd8bd6 100644 --- a/app/cli/main.go +++ b/app/cli/main.go @@ -255,11 +255,11 @@ func main() { log.Fatalf("\nError: could not load current user: %v\n", err) } - mn, err := connectivity.StartTor(path.Join(usr.HomeDir, ".cwtch"), "") + acn, err := connectivity.StartTor(path.Join(usr.HomeDir, ".cwtch"), "") if err != nil { log.Fatalf("\nError connecting to Tor: %v\n", err) } - app = app2.NewApp(mn, path.Join(usr.HomeDir, ".cwtch")) + app = app2.NewApp(acn, path.Join(usr.HomeDir, ".cwtch")) if err != nil { log.Fatalf("Error initializing application: %v", err) } @@ -602,6 +602,6 @@ func main() { } app.Shutdown() - mn.Close() + acn.Close() os.Exit(0) } diff --git a/peer/connections/connectionsmanager.go b/peer/connections/connectionsmanager.go index 8380fed..08b1462 100644 --- a/peer/connections/connectionsmanager.go +++ b/peer/connections/connectionsmanager.go @@ -15,13 +15,13 @@ type Manager struct { serverConnections map[string]*PeerServerConnection lock sync.Mutex breakChannel chan bool - mn connectivity.ACN + acn connectivity.ACN } // NewConnectionsManager creates a new instance of Manager. -func NewConnectionsManager(mn connectivity.ACN) *Manager { +func NewConnectionsManager(acn connectivity.ACN) *Manager { m := new(Manager) - m.mn = mn + m.acn = acn m.peerConnections = make(map[string]*PeerPeerConnection) m.serverConnections = make(map[string]*PeerServerConnection) m.breakChannel = make(chan bool) @@ -35,7 +35,7 @@ func (m *Manager) ManagePeerConnection(host string, profile *model.Profile, data _, exists := m.peerConnections[host] if !exists { - ppc := NewPeerPeerConnection(m.mn, host, profile, dataHandler, aif) + ppc := NewPeerPeerConnection(m.acn, host, profile, dataHandler, aif) go ppc.Run() m.peerConnections[host] = ppc return ppc @@ -49,7 +49,7 @@ func (m *Manager) ManageServerConnection(host string, handler func(string, *prot _, exists := m.serverConnections[host] if !exists { - psc := NewPeerServerConnection(m.mn, host) + psc := NewPeerServerConnection(m.acn, host) go psc.Run() psc.GroupMessageHandler = handler m.serverConnections[host] = psc diff --git a/peer/connections/peerpeerconnection.go b/peer/connections/peerpeerconnection.go index 7db1cea..6e34133 100644 --- a/peer/connections/peerpeerconnection.go +++ b/peer/connections/peerpeerconnection.go @@ -23,13 +23,13 @@ type PeerPeerConnection struct { profile *model.Profile dataHandler func(string, []byte) []byte aif application.ApplicationInstanceFactory - mn connectivity.ACN + acn connectivity.ACN } // NewPeerPeerConnection creates a new peer connection for the given hostname and profile. -func NewPeerPeerConnection(mn connectivity.ACN, peerhostname string, profile *model.Profile, dataHandler func(string, []byte) []byte, aif application.ApplicationInstanceFactory) *PeerPeerConnection { +func NewPeerPeerConnection(acn connectivity.ACN, peerhostname string, profile *model.Profile, dataHandler func(string, []byte) []byte, aif application.ApplicationInstanceFactory) *PeerPeerConnection { ppc := new(PeerPeerConnection) - ppc.mn = mn + ppc.acn = acn ppc.PeerHostname = peerhostname ppc.profile = profile ppc.dataHandler = dataHandler @@ -110,7 +110,7 @@ func (ppc *PeerPeerConnection) WaitTilAuthenticated() { // Run manages the setup and teardown of a peer->peer connection func (ppc *PeerPeerConnection) Run() error { ppc.state = CONNECTING - rc, err := goricochet.Open(ppc.mn, ppc.PeerHostname) + rc, err := goricochet.Open(ppc.acn, ppc.PeerHostname) if err == nil { rc.TraceLog(false) ppc.connection = rc diff --git a/peer/connections/peerserverconnection.go b/peer/connections/peerserverconnection.go index baf65d4..eef8f98 100644 --- a/peer/connections/peerserverconnection.go +++ b/peer/connections/peerserverconnection.go @@ -23,15 +23,15 @@ type PeerServerConnection struct { Server string state ConnectionState connection *connection.Connection - mn connectivity.ACN + acn connectivity.ACN GroupMessageHandler func(string, *protocol.GroupMessage) } // NewPeerServerConnection creates a new Peer->Server outbound connection -func NewPeerServerConnection(mn connectivity.ACN, serverhostname string) *PeerServerConnection { +func NewPeerServerConnection(acn connectivity.ACN, serverhostname string) *PeerServerConnection { psc := new(PeerServerConnection) - psc.mn = mn + psc.acn = acn psc.Server = serverhostname psc.Init() return psc @@ -55,7 +55,7 @@ func (psc *PeerServerConnection) WaitTilAuthenticated() { // Run manages the setup and teardown of a peer server connection func (psc *PeerServerConnection) Run() error { log.Printf("Connecting to %v", psc.Server) - rc, err := goricochet.Open(psc.mn, psc.Server) + rc, err := goricochet.Open(psc.acn, psc.Server) if err == nil { rc.TraceLog(true) psc.connection = rc diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 783ac44..4bd89d2 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -28,7 +28,7 @@ type cwtchPeer struct { connection.AutoConnectionHandler Profile *model.Profile app *application.RicochetApplication - mn connectivity.ACN + acn connectivity.ACN mutex sync.Mutex connectionsManager *connections.Manager dataHandler func(string, []byte) []byte @@ -91,9 +91,9 @@ func FromProfile(profile *model.Profile) CwtchPeer { } // Init instantiates a cwtchPeer -func (cp *cwtchPeer) Init(mn connectivity.ACN) { - cp.mn = mn - cp.connectionsManager = connections.NewConnectionsManager(cp.mn) +func (cp *cwtchPeer) Init(acn connectivity.ACN) { + cp.acn = acn + cp.connectionsManager = connections.NewConnectionsManager(cp.acn) go cp.connectionsManager.AttemptReconnections() } @@ -317,7 +317,7 @@ func (cp *cwtchPeer) Listen() { // Listen sets up an onion listener to process incoming cwtch messages func (cp *cwtchPeer) listenFn() error { ra := new(application.RicochetApplication) - onionService, err := cp.mn.Listen(cp.Profile.Ed25519PrivateKey, application.RicochetPort) + onionService, err := cp.acn.Listen(cp.Profile.Ed25519PrivateKey, application.RicochetPort) if err != nil /*&& fmt.Sprintf("%v", err) != "550 Unspecified Tor error: Onion address collision"*/ { return err } @@ -351,7 +351,7 @@ func (cp *cwtchPeer) listenFn() error { af.AddHandler(handlers[i], cp.aif.GetHandler(handlers[i])) } - ra.Init(cp.mn, cp.Profile.Name, identity.InitializeV3(cp.Profile.Name, &cp.Profile.Ed25519PrivateKey, &cp.Profile.Ed25519PublicKey), af, cp) + ra.Init(cp.acn, cp.Profile.Name, identity.InitializeV3(cp.Profile.Name, &cp.Profile.Ed25519PrivateKey, &cp.Profile.Ed25519PublicKey), af, cp) log.Printf("Running cwtch peer on %v", onionService.AddressFull()) cp.app = ra cp.started = true diff --git a/server/app/main.go b/server/app/main.go index 71c1861..f20da29 100644 --- a/server/app/main.go +++ b/server/app/main.go @@ -17,16 +17,16 @@ func main() { serverConfig := cwtchserver.LoadConfig(configDir, serverConfigFile) - mn, err := connectivity.StartTor(path.Join(configDir, "tor"), "") + acn, err := connectivity.StartTor(path.Join(configDir, "tor"), "") if err != nil { log.Fatalf("\nError connecting to Tor: %v\n", err) } - defer mn.Close() + defer acn.Close() server := new(cwtchserver.Server) log.Printf("starting cwtch server...") // TODO load params from .cwtch/server.conf or command line flag // TODO: respond to HUP so t.Close is gracefully called - server.Run(mn, serverConfig) + server.Run(acn, serverConfig) } diff --git a/server/server.go b/server/server.go index 16f48cb..d1d6bfb 100644 --- a/server/server.go +++ b/server/server.go @@ -23,12 +23,12 @@ type Server struct { // TODO: surface errors // TODO: handle HUP/KILL signals to exit and close Tor gracefully // TODO: handle user input to exit -func (s *Server) Run(mn connectivity.ACN, serverConfig Config) { +func (s *Server) Run(acn connectivity.ACN, serverConfig Config) { s.config = serverConfig cwtchserver := new(application.RicochetApplication) s.metricsPack.Start(cwtchserver, serverConfig.ConfigDir, s.config.ServerReporting.LogMetricsToFile) - listenService, err := mn.Listen(s.config.PrivateKey, application.RicochetPort) + listenService, err := acn.Listen(s.config.PrivateKey, application.RicochetPort) if err != nil { log.Fatalf("error setting up onion service: %v", err) @@ -68,7 +68,7 @@ func (s *Server) Run(mn connectivity.ACN, serverConfig Config) { } }) - cwtchserver.Init(mn, "cwtch server for "+listenService.AddressIdentity(), s.config.Identity(), af, new(application.AcceptAllContactManager)) + cwtchserver.Init(acn, "cwtch server for "+listenService.AddressIdentity(), s.config.Identity(), af, new(application.AcceptAllContactManager)) log.Printf("cwtch server running on cwtch:%s", listenService.AddressFull()) s.app = cwtchserver s.app.Run(listenService) diff --git a/testing/cwtch_peer_server_intergration_test.go b/testing/cwtch_peer_server_intergration_test.go index 0e8bde2..9593f60 100644 --- a/testing/cwtch_peer_server_intergration_test.go +++ b/testing/cwtch_peer_server_intergration_test.go @@ -101,7 +101,7 @@ func TestCwtchPeerIntegration(t *testing.T) { log.SetOutput(ioutil.Discard) numGoRoutinesStart := runtime.NumGoroutine() - mn, err := connectivity.StartTor(".", "") + acn, err := connectivity.StartTor(".", "") if err != nil { t.Fatalf("Could not start Tor: %v", err) } @@ -121,7 +121,7 @@ func TestCwtchPeerIntegration(t *testing.T) { config := cwtchserver.LoadConfig(".", "server-test.json") identity := config.Identity() serverAddr = identity.Hostname() - go server.Run(mn, config) + go server.Run(acn, config) // let tor get established fmt.Printf("Establishing Tor hidden service: %v...\n", serverAddr) @@ -135,19 +135,19 @@ func TestCwtchPeerIntegration(t *testing.T) { fmt.Println("Creating Alice...") alice := peer.NewCwtchPeer("Alice") - alice.Init(mn) + alice.Init(acn) alice.Listen() fmt.Println("Alice created:", alice.GetProfile().Onion) fmt.Println("Creating Bob...") bob := peer.NewCwtchPeer("Bob") - bob.Init(mn) + bob.Init(acn) bob.Listen() fmt.Println("Bob created:", bob.GetProfile().Onion) fmt.Println("Creating Carol...") carol := peer.NewCwtchPeer("Carol") - carol.Init(mn) + carol.Init(acn) carol.Listen() fmt.Println("Carol created:", carol.GetProfile().Onion)