From 712527cc6fe4dc77ed2524e7658898c8c25fe553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Wed, 27 Mar 2019 23:16:26 +0000 Subject: [PATCH 1/3] add peer protection capability to conn mgr. --- interface.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interface.go b/interface.go index 452d79b..9451c67 100644 --- a/interface.go +++ b/interface.go @@ -31,6 +31,12 @@ type ConnManager interface { // Notifee returns an implementation that can be called back to inform of // opened and closed connections. Notifee() inet.Notifiee + + // Protect protects a peer from having its connection(s) pruned. + Protect(peer.ID) + + // Unprotect removes any protection that may have been placed on a peer. + Unprotect(peer.ID) } // TagInfo stores metadata associated with a peer. From 901bea3e15e2186ff465936da9cfc92ab8bfe25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Fri, 29 Mar 2019 12:44:34 +0000 Subject: [PATCH 2/3] scope peer protection under a tag. --- interface.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/interface.go b/interface.go index 9451c67..5a5716a 100644 --- a/interface.go +++ b/interface.go @@ -5,7 +5,7 @@ import ( "time" inet "github.com/libp2p/go-libp2p-net" - "github.com/libp2p/go-libp2p-peer" + peer "github.com/libp2p/go-libp2p-peer" ) // ConnManager tracks connections to peers, and allows consumers to associate metadata @@ -33,10 +33,16 @@ type ConnManager interface { Notifee() inet.Notifiee // Protect protects a peer from having its connection(s) pruned. - Protect(peer.ID) - - // Unprotect removes any protection that may have been placed on a peer. - Unprotect(peer.ID) + // + // Calls to Protect() with the same tag are idempotent. They are not refcounted, so after multiple Protect() + // calls with the same tag, a single Unprotect() call bearing the same tag will revoke the protection. + Protect(id peer.ID, tag string) + + // Unprotect removes a protection that may have been placed on a peer, under the specified tag. + // + // The return value indicates whether the peer continues to be protected after this call, by way of a different tag. + // See notes on Protect() for more info. + Unprotect(id peer.ID, tag string) (protected bool) } // TagInfo stores metadata associated with a peer. From d342b88bdd5facda2fec9b55d74cdb77f76e18cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Fri, 29 Mar 2019 13:08:47 +0000 Subject: [PATCH 3/3] clarify godoc around protection. --- interface.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface.go b/interface.go index 5a5716a..8b5faf0 100644 --- a/interface.go +++ b/interface.go @@ -34,8 +34,10 @@ type ConnManager interface { // Protect protects a peer from having its connection(s) pruned. // - // Calls to Protect() with the same tag are idempotent. They are not refcounted, so after multiple Protect() - // calls with the same tag, a single Unprotect() call bearing the same tag will revoke the protection. + // Tagging allows different parts of the system to manage protections without interfering with one another. + // + // Calls to Protect() with the same tag are idempotent. They are not refcounted, so after multiple calls + // to Protect() with the same tag, a single Unprotect() call bearing the same tag will revoke the protection. Protect(id peer.ID, tag string) // Unprotect removes a protection that may have been placed on a peer, under the specified tag.