forked from cwtch.im/cwtch
API for Block/Allow Unknown Connections
This was previously an application level setting handled by the UI. This commit pushes back that functionality to the profile.
This commit is contained in:
parent
b268a44287
commit
296dc22b8e
|
@ -43,6 +43,17 @@ type cwtchPeer struct {
|
||||||
eventBus event.Manager
|
eventBus event.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlockUnknownConnections will auto disconnect from connections if authentication doesn't resolve a hostname
|
||||||
|
// known to peer.
|
||||||
|
func (cp *cwtchPeer) BlockUnknownConnections() {
|
||||||
|
cp.eventBus.Publish(event.NewEvent(event.BlockUnknownPeers, map[event.Field]string{}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllowUnknownConnections will permit connections from unknown contacts.
|
||||||
|
func (cp *cwtchPeer) AllowUnknownConnections() {
|
||||||
|
cp.eventBus.Publish(event.NewEvent(event.AllowUnknownPeers, map[event.Field]string{}))
|
||||||
|
}
|
||||||
|
|
||||||
// ReadContacts is a meta-interface intended to restrict callers to read-only access to contacts
|
// ReadContacts is a meta-interface intended to restrict callers to read-only access to contacts
|
||||||
type ReadContacts interface {
|
type ReadContacts interface {
|
||||||
GetContacts() []string
|
GetContacts() []string
|
||||||
|
@ -65,6 +76,8 @@ type AccessPeeringState interface {
|
||||||
|
|
||||||
// ModifyPeeringState is a meta-interface intended to restrict callers to modify-only access to connection peers
|
// ModifyPeeringState is a meta-interface intended to restrict callers to modify-only access to connection peers
|
||||||
type ModifyPeeringState interface {
|
type ModifyPeeringState interface {
|
||||||
|
BlockUnknownConnections()
|
||||||
|
AllowUnknownConnections()
|
||||||
PeerWithOnion(string)
|
PeerWithOnion(string)
|
||||||
JoinServer(string) error
|
JoinServer(string) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,9 +144,9 @@ func (e *engine) eventHandler() {
|
||||||
case event.DeleteGroup:
|
case event.DeleteGroup:
|
||||||
// TODO: There isn't a way here to determine if other Groups are using a server connection...
|
// TODO: There isn't a way here to determine if other Groups are using a server connection...
|
||||||
case event.SendMessageToGroup:
|
case event.SendMessageToGroup:
|
||||||
ciphertext,_ := base64.StdEncoding.DecodeString(ev.Data[event.Ciphertext])
|
ciphertext, _ := base64.StdEncoding.DecodeString(ev.Data[event.Ciphertext])
|
||||||
signature,_ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
|
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
|
||||||
err := e.sendMessageToGroup(ev.Data[event.GroupServer],ciphertext, signature)
|
err := e.sendMessageToGroup(ev.Data[event.GroupServer], ciphertext, signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.eventManager.Publish(event.NewEvent(event.SendMessageToGroupError, map[event.Field]string{event.GroupServer: ev.Data[event.GroupServer], event.EventID: ev.EventID, event.Error: err.Error()}))
|
e.eventManager.Publish(event.NewEvent(event.SendMessageToGroupError, map[event.Field]string{event.GroupServer: ev.Data[event.GroupServer], event.EventID: ev.EventID, event.Error: err.Error()}))
|
||||||
}
|
}
|
||||||
|
@ -178,8 +178,10 @@ func (e *engine) eventHandler() {
|
||||||
e.peerDisconnected(ev.Data[event.RemotePeer])
|
e.peerDisconnected(ev.Data[event.RemotePeer])
|
||||||
}
|
}
|
||||||
case event.AllowUnknownPeers:
|
case event.AllowUnknownPeers:
|
||||||
|
log.Debugf("%v now allows unknown connections", e.identity.Hostname())
|
||||||
e.blockUnknownContacts = false
|
e.blockUnknownContacts = false
|
||||||
case event.BlockUnknownPeers:
|
case event.BlockUnknownPeers:
|
||||||
|
log.Debugf("%v now forbids unknown connections", e.identity.Hostname())
|
||||||
e.blockUnknownContacts = true
|
e.blockUnknownContacts = true
|
||||||
case event.ProtocolEngineStartListen:
|
case event.ProtocolEngineStartListen:
|
||||||
go e.listenFn()
|
go e.listenFn()
|
||||||
|
|
Loading…
Reference in New Issue