Merge pull request 'Prefer public.profile.name - ensure that it is consistent with local.profile.name.' (#398) from publicnameprefer into master
Reviewed-on: #398 Reviewed-by: Dan Ballard <dan@openprivacy.ca>
This commit is contained in:
commit
be361384df
|
@ -16,7 +16,7 @@ func WaitGetPeer(app app2.Application, name string) peer.CwtchPeer {
|
||||||
for {
|
for {
|
||||||
for _, handle := range app.ListProfiles() {
|
for _, handle := range app.ListProfiles() {
|
||||||
peer := app.GetPeer(handle)
|
peer := app.GetPeer(handle)
|
||||||
localName, _ := peer.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name)
|
localName, _ := peer.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
|
||||||
if localName == name {
|
if localName == name {
|
||||||
return peer
|
return peer
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,11 +80,19 @@ func (scope Scope) IsConversation() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLocalScope takes a path and attaches the local scope to it
|
// GetLocalScope takes a path and attaches the local scope to it
|
||||||
|
// Deprecated: Use ConstructScopedZonedPath
|
||||||
func GetLocalScope(path string) string {
|
func GetLocalScope(path string) string {
|
||||||
return string(LocalScope) + Separator + path
|
return string(LocalScope) + Separator + path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPublicScope takes a path and attaches the local scope to it
|
||||||
|
// Deprecated: Use ConstructScopedZonedPath
|
||||||
|
func GetPublicScope(path string) string {
|
||||||
|
return string(PublicScope) + Separator + path
|
||||||
|
}
|
||||||
|
|
||||||
// GetPeerScope takes a path and attaches the peer scope to it
|
// GetPeerScope takes a path and attaches the peer scope to it
|
||||||
|
// Deprecated: Use ConstructScopedZonedPath
|
||||||
func GetPeerScope(path string) string {
|
func GetPeerScope(path string) string {
|
||||||
return string(PeerScope) + Separator + path
|
return string(PeerScope) + Separator + path
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,22 +280,49 @@ func FromProfile(profile *model.Profile) CwtchPeer {
|
||||||
func (cp *cwtchPeer) Init(eventBus event.Manager) {
|
func (cp *cwtchPeer) Init(eventBus event.Manager) {
|
||||||
cp.InitForEvents(eventBus, DefaultEventsToHandle)
|
cp.InitForEvents(eventBus, DefaultEventsToHandle)
|
||||||
|
|
||||||
|
|
||||||
// Upgrade the Cwtch Peer if necessary
|
// Upgrade the Cwtch Peer if necessary
|
||||||
// It would be nice to do these checks in the storage engine itself, but it is easier to do them here
|
// It would be nice to do these checks in the storage engine itself, but it is easier to do them here
|
||||||
// rather than duplicating the logic to construct/reconstruct attributes in storage engine...
|
// rather than duplicating the logic to construct/reconstruct attributes in storage engine...
|
||||||
// TODO: Remove these checks after Cwtch ~1.5
|
// TODO: Remove these checks after Cwtch ~1.5 storage engine is implemented
|
||||||
// If local.profile.name does not exist then set it from deprecated GetAttribute
|
if _, exists := cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name); !exists {
|
||||||
if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name); !exists {
|
// If public.profile.name does not exist, and we have an existing public.name then:
|
||||||
if name, exists := cp.Profile.GetAttribute(attr.GetLocalScope(constants.Name)); exists {
|
// set public.profile.name from public.name
|
||||||
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name)
|
// set local.profile.name from public.name
|
||||||
} else if name, exists := cp.Profile.GetAttribute(constants.Name); exists {
|
if name, exists := cp.Profile.GetAttribute(attr.GetPublicScope(constants.Name)); exists {
|
||||||
|
cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, name)
|
||||||
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name)
|
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name)
|
||||||
} else {
|
} else {
|
||||||
// Profile.Name is very deprecated at this point...
|
// Otherwise check if local.name exists and set it from that
|
||||||
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, cp.Profile.Name)
|
// If not, then check the very old unzoned, unscoped name.
|
||||||
|
// If not, then set directly from Profile.Name...
|
||||||
|
if name, exists := cp.Profile.GetAttribute(attr.GetLocalScope(constants.Name)); exists {
|
||||||
|
cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, name)
|
||||||
|
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name)
|
||||||
|
} else if name, exists := cp.Profile.GetAttribute(constants.Name); exists {
|
||||||
|
cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, name)
|
||||||
|
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name)
|
||||||
|
} else {
|
||||||
|
// Profile.Name is very deprecated at this point...
|
||||||
|
cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, cp.Profile.Name)
|
||||||
|
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, cp.Profile.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point we can safely assume that public.profile.name exists
|
||||||
|
localName, _ := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name)
|
||||||
|
publicName, _ := cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
|
||||||
|
|
||||||
|
if localName != publicName {
|
||||||
|
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, publicName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point we can safely assume that public.profile.name exists AND is consistent with
|
||||||
|
// local.profile.name - regardless of whatever Cwtch version we have upgraded from. This will
|
||||||
|
// be important after Cwtch 1.5 when we purge all previous references to local.profile.name and
|
||||||
|
// profile-> name - and remove all name processing code from libcwtch-go.
|
||||||
|
|
||||||
// If local.profile.tag does not exist then set it from deprecated GetAttribute
|
// If local.profile.tag does not exist then set it from deprecated GetAttribute
|
||||||
if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag); !exists {
|
if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag); !exists {
|
||||||
if tag, exists := cp.Profile.GetAttribute(constants.Tag); exists {
|
if tag, exists := cp.Profile.GetAttribute(constants.Tag); exists {
|
||||||
|
|
|
@ -171,7 +171,7 @@ func (ta *TokenBoardClient) Post(ct []byte, sig []byte) (bool, int) {
|
||||||
|
|
||||||
// MakePayment uses the PoW based token protocol to obtain more tokens
|
// MakePayment uses the PoW based token protocol to obtain more tokens
|
||||||
func (ta *TokenBoardClient) MakePayment() error {
|
func (ta *TokenBoardClient) MakePayment() error {
|
||||||
log.Debugf("Making a Payment %v", ta)
|
log.Debugf("Making a Payment")
|
||||||
id, sk := primitives.InitializeEphemeralIdentity()
|
id, sk := primitives.InitializeEphemeralIdentity()
|
||||||
client := new(tor.BaseOnionService)
|
client := new(tor.BaseOnionService)
|
||||||
client.Init(ta.acn, sk, &id)
|
client.Init(ta.acn, sk, &id)
|
||||||
|
@ -201,7 +201,7 @@ func (ta *TokenBoardClient) MakePayment() error {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Errorf("invalid cast of powapp. this should not happen %v %v", powtapp, reflect.TypeOf(conn.App()))
|
log.Errorf("invalid cast of powapp. this should never happen %v %v", powtapp, reflect.TypeOf(conn.App()))
|
||||||
return errors.New("invalid cast of powapp. this should never happen")
|
return errors.New("invalid cast of powapp. this should never happen")
|
||||||
}
|
}
|
||||||
log.Debugf("could not connect to payment server %v..trying again")
|
log.Debugf("could not connect to payment server %v..trying again")
|
||||||
|
|
Loading…
Reference in New Issue