2018-05-25 09:05:35 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2019-09-11 05:48:34 +00:00
|
|
|
"errors"
|
|
|
|
|
2018-05-25 09:05:35 +00:00
|
|
|
"github.com/ipfs/ipfs-cluster/api"
|
|
|
|
|
2019-06-14 10:41:11 +00:00
|
|
|
peer "github.com/libp2p/go-libp2p-core/peer"
|
2018-05-25 09:05:35 +00:00
|
|
|
)
|
|
|
|
|
2019-09-11 05:48:34 +00:00
|
|
|
var (
|
|
|
|
// ErrFullQueue is the error used when pin or unpin operation channel is full.
|
|
|
|
ErrFullQueue = errors.New("pin/unpin operation queue is full (too many operations), increasing max_pin_queue_size would help")
|
|
|
|
)
|
|
|
|
|
2018-05-25 09:05:35 +00:00
|
|
|
// IsRemotePin determines whether a Pin's ReplicationFactor has
|
|
|
|
// been met, so as to either pin or unpin it from the peer.
|
2019-02-27 17:04:35 +00:00
|
|
|
func IsRemotePin(c *api.Pin, pid peer.ID) bool {
|
2018-05-25 09:05:35 +00:00
|
|
|
if c.ReplicationFactorMax < 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range c.Allocations {
|
|
|
|
if p == pid {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|