diff --git a/app/app.go b/app/app.go index b21821d..7c5fd76 100644 --- a/app/app.go +++ b/app/app.go @@ -133,7 +133,7 @@ func (app *application) CreateTaggedPeer(name string, password string, tag strin 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) @@ -221,7 +221,7 @@ func (app *application) LoadProfiles(password string) { app.storage[profile.Onion] = profileStore app.engines[profile.Onion] = engine 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++ }) if count == 0 { diff --git a/app/appClient.go b/app/appClient.go index 14a52ea..2330951 100644 --- a/app/appClient.go +++ b/app/appClient.go @@ -45,7 +45,8 @@ func (ac *applicationClient) handleEvent(ev *event.Event) { key := ev.Data[event.Key] salt := ev.Data[event.Salt] 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: onion := ev.Data[event.Identity] 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 saltBytes [128]byte copy(keyBytes[:], key) @@ -87,9 +88,9 @@ func (ac *applicationClient) newPeer(localID, key, salt string, reload bool) { defer ac.peerLock.Unlock() ac.peers[profile.Onion] = peer 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 { - npEvent.Data[event.Status] = "running" + npEvent.Data[event.Status] = event.StorageRunning } ac.appBus.Publish(npEvent) diff --git a/app/appService.go b/app/appService.go index ea03105..1a25e8f 100644 --- a/app/appService.go +++ b/app/appService.go @@ -67,6 +67,7 @@ func (as *applicationService) handleEvent(ev *event.Event) { for _, storage := range as.storage { peerMsg := *storage.GetNewPeerMessage() peerMsg.Data[event.Status] = event.StorageRunning + peerMsg.Data[event.Created] = event.False message := event.IPCMessage{Dest: DestApp, Message: peerMsg} as.bridge.Write(&message) } @@ -116,6 +117,7 @@ func (as *applicationService) createPeer(name, password, tag string) { as.engines[profile.Onion] = engine peerMsg := *profileStore.GetNewPeerMessage() + peerMsg.Data[event.Created] = event.True peerMsg.Data[event.Status] = event.StorageNew message := event.IPCMessage{Dest: DestApp, Message: peerMsg} as.bridge.Write(&message) @@ -135,6 +137,7 @@ func (as *applicationService) loadProfiles(password string) { as.asmutex.Unlock() peerMsg := *profileStore.GetNewPeerMessage() + peerMsg.Data[event.Created] = event.False peerMsg.Data[event.Status] = event.StorageNew message := event.IPCMessage{Dest: DestApp, Message: peerMsg} as.bridge.Write(&message) diff --git a/event/common.go b/event/common.go index ffe6a8a..dd3d286 100644 --- a/event/common.go +++ b/event/common.go @@ -156,8 +156,8 @@ const ( // ProfileName, Password, Data(tag) CreatePeer = Type("CreatePeer") - // service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')] - // app -> Key, Salt + // app: Identity(onion), Created(bool) + // service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')], Created(bool) NewPeer = Type("NewPeer") // Identity(onion) @@ -233,6 +233,8 @@ const ( Password = Field("Password") NewPassword = Field("NewPassword") + Created = Field("Created") + ConnectionState = Field("ConnectionState") Key = Field("Key") @@ -292,3 +294,9 @@ const ( SaveHistoryConfirmed = "SaveHistory" DeleteHistoryConfirmed = "DeleteHistoryConfirmed" ) + +// Bool strings +const ( + True = "true" + False = "false" +) \ No newline at end of file