forked from cwtch.im/cwtch
little fixes
This commit is contained in:
parent
07ffd780b0
commit
3b932bedc0
11
app/app.go
11
app/app.go
|
@ -34,6 +34,7 @@ type Application interface {
|
|||
PrimaryIdentity() peer.CwtchPeer
|
||||
GetPeer(onion string) peer.CwtchPeer
|
||||
ListPeers() map[string]string
|
||||
LaunchPeers()
|
||||
|
||||
GetTorStatus() (map[string]string, error)
|
||||
|
||||
|
@ -104,7 +105,6 @@ func (app *application) LoadProfiles(password string) error {
|
|||
|
||||
p, err := fileStore.Load()
|
||||
if err != nil {
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,6 @@ func (app *application) LoadProfiles(password string) error {
|
|||
log.Printf("Error: profile for onion %v already exists", p.GetProfile().Onion)
|
||||
continue
|
||||
}
|
||||
app.startPeer(p)
|
||||
app.mutex.Lock()
|
||||
app.peers[p.GetProfile().Onion] = p
|
||||
app.storage[p.GetProfile().Onion] = fileStore
|
||||
|
@ -151,6 +150,14 @@ func (app *application) startTor(torPath string) error {
|
|||
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() {
|
||||
e := peer.Listen()
|
||||
|
|
|
@ -29,8 +29,8 @@ type cwtchPeer struct {
|
|||
mutex sync.Mutex
|
||||
connectionsManager *connections.Manager
|
||||
dataHandler func(string, []byte) []byte
|
||||
//handlers map[string]func(*application.ApplicationInstance) func() channels.Handler
|
||||
aif application.ApplicationInstanceFactory
|
||||
started bool
|
||||
}
|
||||
|
||||
// CwtchPeer provides us with a way of testing systems built on top of cwtch without having to
|
||||
|
@ -66,6 +66,7 @@ type CwtchPeer interface {
|
|||
SetApplicationInstanceFactory(factory application.ApplicationInstanceFactory)
|
||||
SetPeerDataHandler(func(string, []byte) []byte)
|
||||
|
||||
IsStarted() bool
|
||||
Listen() error
|
||||
Shutdown()
|
||||
}
|
||||
|
@ -335,6 +336,7 @@ func (cp *cwtchPeer) Listen() error {
|
|||
cwtchpeer.InitV3(cp.Profile.Name, identity.InitializeV3(cp.Profile.Name, &cp.Profile.Ed25519PrivateKey, &cp.Profile.Ed25519PublicKey), af, cp)
|
||||
log.Printf("Running cwtch peer on %v", l.Addr().String())
|
||||
cp.app = cwtchpeer
|
||||
cp.started = true
|
||||
cwtchpeer.Run(l)
|
||||
return nil
|
||||
}
|
||||
|
@ -347,6 +349,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
|
||||
type CwtchPeerInstance struct {
|
||||
rai *application.ApplicationInstance
|
||||
|
|
|
@ -103,6 +103,7 @@ func (fps *fileProfileStore) Load() (peer.CwtchPeer, error) {
|
|||
if err == nil {
|
||||
return peer.FromProfile(profile), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue