add 'created' field to newPeer message for when it's a newly created peer for ui to trigger new peer actions on
the build was successful Details

This commit is contained in:
Dan Ballard 2020-11-02 14:35:11 -08:00
parent ca7b5aa677
commit 8d59b3b2e3
4 changed files with 20 additions and 8 deletions

View File

@ -133,7 +133,7 @@ func (app *application) CreateTaggedPeer(name string, password string, tag strin
p.SetAttribute(AttributeTag, tag) p.SetAttribute(AttributeTag, tag)
} }
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion})) app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion, event.Created: event.True}))
} }
// CreatePeer creates a new Peer with the given name and required accessories (eventbus, storage, protocol engine) // CreatePeer creates a new Peer with the given name and required accessories (eventbus, storage, protocol engine)
@ -221,7 +221,7 @@ func (app *application) LoadProfiles(password string) {
app.storage[profile.Onion] = profileStore app.storage[profile.Onion] = profileStore
app.engines[profile.Onion] = engine app.engines[profile.Onion] = engine
app.appmutex.Unlock() app.appmutex.Unlock()
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion})) app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion, event.Created: event.False}))
count++ count++
}) })
if count == 0 { if count == 0 {

View File

@ -45,7 +45,8 @@ func (ac *applicationClient) handleEvent(ev *event.Event) {
key := ev.Data[event.Key] key := ev.Data[event.Key]
salt := ev.Data[event.Salt] salt := ev.Data[event.Salt]
reload := ev.Data[event.Status] == event.StorageRunning reload := ev.Data[event.Status] == event.StorageRunning
ac.newPeer(localID, key, salt, reload) created := ev.Data[event.Created]
ac.newPeer(localID, key, salt, reload, created)
case event.DeletePeer: case event.DeletePeer:
onion := ev.Data[event.Identity] onion := ev.Data[event.Identity]
ac.handleDeletedPeer(onion) ac.handleDeletedPeer(onion)
@ -60,7 +61,7 @@ func (ac *applicationClient) handleEvent(ev *event.Event) {
} }
} }
func (ac *applicationClient) newPeer(localID, key, salt string, reload bool) { func (ac *applicationClient) newPeer(localID, key, salt string, reload bool, created string) {
var keyBytes [32]byte var keyBytes [32]byte
var saltBytes [128]byte var saltBytes [128]byte
copy(keyBytes[:], key) copy(keyBytes[:], key)
@ -87,9 +88,9 @@ func (ac *applicationClient) newPeer(localID, key, salt string, reload bool) {
defer ac.peerLock.Unlock() defer ac.peerLock.Unlock()
ac.peers[profile.Onion] = peer ac.peers[profile.Onion] = peer
ac.eventBuses[profile.Onion] = eventBus ac.eventBuses[profile.Onion] = eventBus
npEvent := event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion}) npEvent := event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion, event.Created: created})
if reload { if reload {
npEvent.Data[event.Status] = "running" npEvent.Data[event.Status] = event.StorageRunning
} }
ac.appBus.Publish(npEvent) ac.appBus.Publish(npEvent)

View File

@ -67,6 +67,7 @@ func (as *applicationService) handleEvent(ev *event.Event) {
for _, storage := range as.storage { for _, storage := range as.storage {
peerMsg := *storage.GetNewPeerMessage() peerMsg := *storage.GetNewPeerMessage()
peerMsg.Data[event.Status] = event.StorageRunning peerMsg.Data[event.Status] = event.StorageRunning
peerMsg.Data[event.Created] = event.False
message := event.IPCMessage{Dest: DestApp, Message: peerMsg} message := event.IPCMessage{Dest: DestApp, Message: peerMsg}
as.bridge.Write(&message) as.bridge.Write(&message)
} }
@ -116,6 +117,7 @@ func (as *applicationService) createPeer(name, password, tag string) {
as.engines[profile.Onion] = engine as.engines[profile.Onion] = engine
peerMsg := *profileStore.GetNewPeerMessage() peerMsg := *profileStore.GetNewPeerMessage()
peerMsg.Data[event.Created] = event.True
peerMsg.Data[event.Status] = event.StorageNew peerMsg.Data[event.Status] = event.StorageNew
message := event.IPCMessage{Dest: DestApp, Message: peerMsg} message := event.IPCMessage{Dest: DestApp, Message: peerMsg}
as.bridge.Write(&message) as.bridge.Write(&message)
@ -135,6 +137,7 @@ func (as *applicationService) loadProfiles(password string) {
as.asmutex.Unlock() as.asmutex.Unlock()
peerMsg := *profileStore.GetNewPeerMessage() peerMsg := *profileStore.GetNewPeerMessage()
peerMsg.Data[event.Created] = event.False
peerMsg.Data[event.Status] = event.StorageNew peerMsg.Data[event.Status] = event.StorageNew
message := event.IPCMessage{Dest: DestApp, Message: peerMsg} message := event.IPCMessage{Dest: DestApp, Message: peerMsg}
as.bridge.Write(&message) as.bridge.Write(&message)

View File

@ -156,8 +156,8 @@ const (
// ProfileName, Password, Data(tag) // ProfileName, Password, Data(tag)
CreatePeer = Type("CreatePeer") CreatePeer = Type("CreatePeer")
// service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')] // app: Identity(onion), Created(bool)
// app -> Key, Salt // service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')], Created(bool)
NewPeer = Type("NewPeer") NewPeer = Type("NewPeer")
// Identity(onion) // Identity(onion)
@ -233,6 +233,8 @@ const (
Password = Field("Password") Password = Field("Password")
NewPassword = Field("NewPassword") NewPassword = Field("NewPassword")
Created = Field("Created")
ConnectionState = Field("ConnectionState") ConnectionState = Field("ConnectionState")
Key = Field("Key") Key = Field("Key")
@ -292,3 +294,9 @@ const (
SaveHistoryConfirmed = "SaveHistory" SaveHistoryConfirmed = "SaveHistory"
DeleteHistoryConfirmed = "DeleteHistoryConfirmed" DeleteHistoryConfirmed = "DeleteHistoryConfirmed"
) )
// Bool strings
const (
True = "true"
False = "false"
)