|
|
@@ -65,13 +65,6 @@ pub async fn remove_sub_on_stop(p2p: P2pPtr, channel: ChannelPtr) {
|
|
|
"Received stop event. Removing channel {}", channel.address(),
|
|
|
);
|
|
|
|
|
|
- // Remove channel from anchorlist
|
|
|
- if p2p.hosts().anchorlist_contains(channel.address()).await {
|
|
|
- let index =
|
|
|
- p2p.hosts().get_anchorlist_index_at_addr(channel.address().clone()).await.unwrap();
|
|
|
- p2p.hosts().anchorlist_remove(channel.address(), index).await;
|
|
|
- }
|
|
|
-
|
|
|
// Remove channel from p2p
|
|
|
p2p.remove(channel).await;
|
|
|
debug!(target: "net::session::remove_sub_on_stop()", "[END]");
|
|
|
@@ -157,7 +150,7 @@ pub trait Session: Sync {
|
|
|
/// Upgrade a connection to the anchorlist and remove it from the white or greylist.
|
|
|
/// Called after a connection has been successfully established in Outbound and Manual
|
|
|
/// sessions.
|
|
|
- async fn upgrade_connection(&self, addr: &Url) {
|
|
|
+ async fn upgrade_host(&self, addr: &Url) {
|
|
|
let hosts = self.p2p().hosts();
|
|
|
|
|
|
let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
@@ -174,6 +167,31 @@ pub trait Session: Sync {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Downgrade a connection. If it's on the anchorlist or the whitelist, remove it and add it
|
|
|
+ /// to the greylist. Called when we cannot establish a connection to a host or when a
|
|
|
+ /// pre-existing connection disconnects.
|
|
|
+ async fn downgrade_host(&self, addr: &Url) {
|
|
|
+ let hosts = self.p2p().hosts();
|
|
|
+
|
|
|
+ // Remove channel from anchorlist and add it to greylist
|
|
|
+ if hosts.anchorlist_contains(addr).await {
|
|
|
+ let (url, last_seen) = hosts.get_anchorlist_entry_at_addr(addr).await.unwrap();
|
|
|
+ hosts.greylist_store_or_update(&[(url, last_seen)]).await;
|
|
|
+
|
|
|
+ let index = hosts.get_anchorlist_index_at_addr(addr.clone()).await.unwrap();
|
|
|
+ hosts.anchorlist_remove(addr, index).await;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Remove channel from whitelist and add to greylist
|
|
|
+ if hosts.whitelist_contains(addr).await {
|
|
|
+ let (url, last_seen) = hosts.get_whitelist_entry_at_addr(addr).await.unwrap();
|
|
|
+ hosts.greylist_store_or_update(&[(url, last_seen)]).await;
|
|
|
+
|
|
|
+ let index = hosts.get_whitelist_index_at_addr(addr.clone()).await.unwrap();
|
|
|
+ hosts.whitelist_remove(addr, index).await;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// Returns a pointer to the p2p network interface
|
|
|
fn p2p(&self) -> P2pPtr;
|
|
|
|