6447ea51d2
This takes advantange of the latest features in go-cid, peer.ID and go-multiaddr and makes the Go types serializable by default. This means we no longer need to copy between Pin <-> PinSerial, or ID <-> IDSerial etc. We can now efficiently binary-encode these types using short field keys and without parsing/stringifying (in many cases it just a cast). We still get the same json output as before (with minor modifications for Cids). This should greatly improve Cluster performance and memory usage when dealing with large collections of items. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
23 lines
418 B
Go
23 lines
418 B
Go
package util
|
|
|
|
import (
|
|
"github.com/ipfs/ipfs-cluster/api"
|
|
|
|
peer "github.com/libp2p/go-libp2p-peer"
|
|
)
|
|
|
|
// IsRemotePin determines whether a Pin's ReplicationFactor has
|
|
// been met, so as to either pin or unpin it from the peer.
|
|
func IsRemotePin(c *api.Pin, pid peer.ID) bool {
|
|
if c.ReplicationFactorMax < 0 {
|
|
return false
|
|
}
|
|
|
|
for _, p := range c.Allocations {
|
|
if p == pid {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|