core: Handle connection close for contacts
This commit is contained in:
parent
289d0f4dc2
commit
114720bd6d
|
@ -191,3 +191,30 @@ func (c *Contact) shouldReplaceConnection(conn *protocol.OpenConnection) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Contact) OnConnectionClosed(conn *protocol.OpenConnection) {
|
||||||
|
c.mutex.Lock()
|
||||||
|
|
||||||
|
if c.connection != conn {
|
||||||
|
c.mutex.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.connection = nil
|
||||||
|
c.status = ricochet.Contact_OFFLINE
|
||||||
|
|
||||||
|
config := c.core.Config.OpenWrite()
|
||||||
|
c.data.LastConnected = time.Now().Format(time.RFC3339)
|
||||||
|
config.Contacts[strconv.Itoa(c.id)] = c.data
|
||||||
|
config.Save()
|
||||||
|
|
||||||
|
c.mutex.Unlock()
|
||||||
|
|
||||||
|
event := ricochet.ContactEvent{
|
||||||
|
Type: ricochet.ContactEvent_UPDATE,
|
||||||
|
Subject: &ricochet.ContactEvent_Contact{
|
||||||
|
Contact: c.Data(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
c.events.Publish(event)
|
||||||
|
}
|
||||||
|
|
|
@ -61,6 +61,16 @@ func (handler *protocolHandler) OnConnect(oc *protocol.OpenConnection) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (handler *protocolHandler) OnDisconnect(oc *protocol.OpenConnection) {
|
||||||
|
log.Printf("protocol: OnDisconnect: %v", oc)
|
||||||
|
if oc.OtherHostname != "" {
|
||||||
|
contact := handler.p.core.Identity.ContactList().ContactByAddress("ricochet:" + oc.OtherHostname)
|
||||||
|
if contact != nil {
|
||||||
|
contact.OnConnectionClosed(oc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Authentication Management
|
// Authentication Management
|
||||||
func (handler *protocolHandler) OnAuthenticationRequest(oc *protocol.OpenConnection, channelID int32, clientCookie [16]byte) {
|
func (handler *protocolHandler) OnAuthenticationRequest(oc *protocol.OpenConnection, channelID int32, clientCookie [16]byte) {
|
||||||
log.Printf("protocol: OnAuthenticationRequest")
|
log.Printf("protocol: OnAuthenticationRequest")
|
||||||
|
|
Loading…
Reference in New Issue