Shortcut for Primary Identity

This commit is contained in:
Sarah Jamie Lewis 2018-10-03 21:35:30 -07:00
parent 85885f183b
commit a2ed058edd
1 changed files with 10 additions and 0 deletions

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 {