|
|
|
@ -38,11 +38,10 @@ type application struct {
|
|
|
|
|
// Application is a full cwtch peer application. It allows management, usage and storage of multiple peers
|
|
|
|
|
type Application interface {
|
|
|
|
|
LoadProfiles(password string)
|
|
|
|
|
CreatePeer(name string, password string, attributes map[attr.ZonedPath]string)
|
|
|
|
|
// Deprecated in 1.10
|
|
|
|
|
CreateTaggedPeer(name string, password string, tag string)
|
|
|
|
|
CreateProfile(name string, password string, autostart bool)
|
|
|
|
|
|
|
|
|
|
ImportProfile(exportedCwtchFile string, password string) (peer.CwtchPeer, error)
|
|
|
|
|
DeletePeer(onion string, currentPassword string)
|
|
|
|
|
DeleteProfile(onion string, currentPassword string)
|
|
|
|
|
AddPeerPlugin(onion string, pluginID plugins.PluginID)
|
|
|
|
|
|
|
|
|
|
GetPrimaryBus() event.Manager
|
|
|
|
@ -51,7 +50,7 @@ type Application interface {
|
|
|
|
|
QueryACNVersion()
|
|
|
|
|
|
|
|
|
|
ActivateEngines(doListn, doPeers, doServers bool)
|
|
|
|
|
ActivatePeerEngine(onion string, doListen, doPeers, doServers bool)
|
|
|
|
|
ActivatePeerEngine(onion string)
|
|
|
|
|
DeactivatePeerEngine(onion string)
|
|
|
|
|
|
|
|
|
|
ReadSettings() GlobalSettings
|
|
|
|
@ -67,8 +66,7 @@ type Application interface {
|
|
|
|
|
// LoadProfileFn is the function signature for a function in an app that loads a profile
|
|
|
|
|
type LoadProfileFn func(profile peer.CwtchPeer)
|
|
|
|
|
|
|
|
|
|
// NewApp creates a new app with some environment awareness and initializes a Tor Manager
|
|
|
|
|
func NewApp(acn connectivity.ACN, appDirectory string) Application {
|
|
|
|
|
func InitApp(appDirectory string) *GlobalSettingsFile {
|
|
|
|
|
log.Debugf("NewApp(%v)\n", appDirectory)
|
|
|
|
|
os.MkdirAll(path.Join(appDirectory, "profiles"), 0700)
|
|
|
|
|
|
|
|
|
@ -79,6 +77,11 @@ func NewApp(acn connectivity.ACN, appDirectory string) Application {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("error initializing global settings file %. Global settings might not be loaded or saves", err)
|
|
|
|
|
}
|
|
|
|
|
return settings
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewApp creates a new app with some environment awareness and initializes a Tor Manager
|
|
|
|
|
func NewApp(acn connectivity.ACN, appDirectory string, settings *GlobalSettingsFile) Application {
|
|
|
|
|
|
|
|
|
|
app := &application{engines: make(map[string]connections.Engine), eventBuses: make(map[string]event.Manager), directory: appDirectory, appBus: event.NewEventManager(), settings: settings}
|
|
|
|
|
app.peers = make(map[string]peer.CwtchPeer)
|
|
|
|
@ -159,6 +162,22 @@ func (ap *application) AddPlugin(peerid string, id plugins.PluginID, bus event.M
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) CreateProfile(name string, password string, autostart bool) {
|
|
|
|
|
autostartVal := constants.True
|
|
|
|
|
if !autostart {
|
|
|
|
|
autostartVal = constants.False
|
|
|
|
|
}
|
|
|
|
|
tagVal := constants.ProfileTypeV1Password
|
|
|
|
|
if password == DefactoPasswordForUnencryptedProfiles {
|
|
|
|
|
tagVal = constants.ProfileTypeV1DefaultPassword
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.CreatePeer(name, password, map[attr.ZonedPath]string{
|
|
|
|
|
attr.ProfileZone.ConstructZonedPath(constants.Tag): tagVal,
|
|
|
|
|
attr.ProfileZone.ConstructZonedPath(constants.PeerAutostart): autostartVal,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deprecated in 1.10
|
|
|
|
|
func (app *application) CreateTaggedPeer(name string, password string, tag string) {
|
|
|
|
|
app.CreatePeer(name, password, map[attr.ZonedPath]string{attr.ProfileZone.ConstructZonedPath(constants.Tag): tag})
|
|
|
|
@ -192,8 +211,8 @@ func (app *application) CreatePeer(name string, password string, attributes map[
|
|
|
|
|
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.GetOnion(), event.Created: event.True}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) DeletePeer(onion string, password string) {
|
|
|
|
|
log.Debugf("DeletePeer called on %v\n", onion)
|
|
|
|
|
func (app *application) DeleteProfile(onion string, password string) {
|
|
|
|
|
log.Debugf("DeleteProfile called on %v\n", onion)
|
|
|
|
|
app.appmutex.Lock()
|
|
|
|
|
defer app.appmutex.Unlock()
|
|
|
|
|
|
|
|
|
@ -333,7 +352,7 @@ func (app *application) ActivateEngines(doListen, doPeers, doServers bool) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ActivePeerEngine creates a peer engine for use with an ACN, should be called once the underlying ACN is online
|
|
|
|
|
func (app *application) ActivatePeerEngine(onion string, doListen, doPeers, doServers bool) {
|
|
|
|
|
func (app *application) ActivatePeerEngine(onion string) {
|
|
|
|
|
profile := app.GetPeer(onion)
|
|
|
|
|
if profile != nil {
|
|
|
|
|
if _, exists := app.engines[onion]; !exists {
|
|
|
|
@ -341,10 +360,10 @@ func (app *application) ActivatePeerEngine(onion string, doListen, doPeers, doSe
|
|
|
|
|
|
|
|
|
|
app.eventBuses[profile.GetOnion()].Publish(event.NewEventList(event.ProtocolEngineCreated))
|
|
|
|
|
app.QueryACNStatus()
|
|
|
|
|
if doListen {
|
|
|
|
|
if true {
|
|
|
|
|
profile.Listen()
|
|
|
|
|
}
|
|
|
|
|
profile.StartConnections(doPeers, doServers)
|
|
|
|
|
profile.StartConnections(true, true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|