forked from cwtch.im/cwtch
local var rename
This commit is contained in:
parent
60fb12054a
commit
8a0d9c54fd
10
app/app.go
10
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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue