little fixes
This commit is contained in:
parent
d06b68d001
commit
ddbf96e668
17
app/app.go
17
app/app.go
|
@ -34,6 +34,7 @@ type Application interface {
|
||||||
PrimaryIdentity() peer.CwtchPeer
|
PrimaryIdentity() peer.CwtchPeer
|
||||||
GetPeer(onion string) peer.CwtchPeer
|
GetPeer(onion string) peer.CwtchPeer
|
||||||
ListPeers() map[string]string
|
ListPeers() map[string]string
|
||||||
|
LaunchPeers()
|
||||||
|
|
||||||
//GetTorStatus() (map[string]string, error)
|
//GetTorStatus() (map[string]string, error)
|
||||||
|
|
||||||
|
@ -108,8 +109,10 @@ func (app *application) LoadProfiles(password string) error {
|
||||||
log.Printf("Error: profile for onion %v already exists", p.GetProfile().Onion)
|
log.Printf("Error: profile for onion %v already exists", p.GetProfile().Onion)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Init(app.mn)
|
p.Init(app.mn)
|
||||||
p.Listen()
|
p.Listen()
|
||||||
|
|
||||||
app.mutex.Lock()
|
app.mutex.Lock()
|
||||||
app.peers[p.GetProfile().Onion] = p
|
app.peers[p.GetProfile().Onion] = p
|
||||||
app.storage[p.GetProfile().Onion] = fileStore
|
app.storage[p.GetProfile().Onion] = fileStore
|
||||||
|
@ -121,6 +124,20 @@ func (app *application) LoadProfiles(password string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *application) LaunchPeers() {
|
||||||
|
for _, p := range app.peers {
|
||||||
|
if !p.IsStarted() {
|
||||||
|
app.startPeer(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *application) startPeer(peer peer.CwtchPeer) {
|
||||||
|
go func() {
|
||||||
|
peer.Listen()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// ListPeers returns a map of onions to their profile's Name
|
// ListPeers returns a map of onions to their profile's Name
|
||||||
func (app *application) ListPeers() map[string]string {
|
func (app *application) ListPeers() map[string]string {
|
||||||
keys := map[string]string{}
|
keys := map[string]string{}
|
||||||
|
|
|
@ -32,9 +32,9 @@ type cwtchPeer struct {
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
connectionsManager *connections.Manager
|
connectionsManager *connections.Manager
|
||||||
dataHandler func(string, []byte) []byte
|
dataHandler func(string, []byte) []byte
|
||||||
//handlers map[string]func(*application.ApplicationInstance) func() channels.Handler
|
|
||||||
aif application.ApplicationInstanceFactory
|
|
||||||
shutdown bool
|
shutdown bool
|
||||||
|
aif application.ApplicationInstanceFactory
|
||||||
|
started bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// CwtchPeer provides us with a way of testing systems built on top of cwtch without having to
|
// CwtchPeer provides us with a way of testing systems built on top of cwtch without having to
|
||||||
|
@ -71,6 +71,7 @@ type CwtchPeer interface {
|
||||||
SetPeerDataHandler(func(string, []byte) []byte)
|
SetPeerDataHandler(func(string, []byte) []byte)
|
||||||
|
|
||||||
Listen()
|
Listen()
|
||||||
|
IsStarted() bool
|
||||||
Shutdown()
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +354,9 @@ func (cp *cwtchPeer) listenFn() error {
|
||||||
ra.Init(cp.mn, cp.Profile.Name, identity.InitializeV3(cp.Profile.Name, &cp.Profile.Ed25519PrivateKey, &cp.Profile.Ed25519PublicKey), af, cp)
|
ra.Init(cp.mn, 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())
|
log.Printf("Running cwtch peer on %v", onionService.AddressFull())
|
||||||
cp.app = ra
|
cp.app = ra
|
||||||
|
cp.started = true
|
||||||
ra.Run(onionService)
|
ra.Run(onionService)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,6 +369,11 @@ func (cp *cwtchPeer) Shutdown() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsStarted returns true if Listen() has successfully been run before on this connection (ever). TODO: we will need to properly unset this flag on error if we want to support resumption in the future
|
||||||
|
func (cp *cwtchPeer) IsStarted() bool {
|
||||||
|
return cp.started
|
||||||
|
}
|
||||||
|
|
||||||
// CwtchPeerInstance encapsulates incoming peer connections
|
// CwtchPeerInstance encapsulates incoming peer connections
|
||||||
type CwtchPeerInstance struct {
|
type CwtchPeerInstance struct {
|
||||||
rai *application.ApplicationInstance
|
rai *application.ApplicationInstance
|
||||||
|
|
|
@ -103,6 +103,7 @@ func (fps *fileProfileStore) Load() (peer.CwtchPeer, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return peer.FromProfile(profile), nil
|
return peer.FromProfile(profile), nil
|
||||||
}
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue