Browse Source

Shortcut for Primary Identity

identity
Sarah Jamie Lewis 1 year ago
parent
commit
a2ed058edd
1 changed files with 10 additions and 0 deletions
  1. +10
    -0
      app/app.go

+ 10
- 0
app/app.go View File

@@ -19,6 +19,7 @@ type application struct {
torManager *tor.Manager
directory string
mutex sync.Mutex
primaryonion string
}

// Application is a full cwtch peer application. It allows management, usage and storage of multiple peers
@@ -26,6 +27,7 @@ type Application interface {
LoadProfiles(password string) error
CreatePeer(name string, password string) (peer.CwtchPeer, error)

PrimaryIdentity() peer.CwtchPeer
GetPeer(onion string) peer.CwtchPeer
ListPeers() map[string]string

@@ -100,6 +102,9 @@ func (app *application) LoadProfiles(password string) error {
app.startPeer(p)
app.mutex.Lock()
app.peers[p.GetProfile().Onion] = p
if app.primaryonion == "" {
app.primaryonion = p.GetProfile().Onion
}
app.mutex.Unlock()
}
return nil
@@ -148,6 +153,11 @@ func (app *application) ListPeers() map[string]string {
return keys
}

// PrimaryIdentity returns a Peer for a given onion address
func (app *application) PrimaryIdentity() peer.CwtchPeer {
return app.peers[app.primaryonion]
}

// GetPeer returns a Peer for a given onion address
func (app *application) GetPeer(onion string) peer.CwtchPeer {
if peer, ok := app.peers[onion]; ok {


Loading…
Cancel
Save