go-libp2p-resource-manager/rcmgr.go

669 lines
13 KiB
Go
Raw Permalink Normal View History

2021-12-23 21:28:14 +08:00
package rcmgr
import (
"context"
2021-12-23 21:28:14 +08:00
"fmt"
2021-12-23 23:46:08 +08:00
"sync"
"time"
2021-12-23 21:28:14 +08:00
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
logging "github.com/ipfs/go-log/v2"
2021-12-23 21:28:14 +08:00
)
var log = logging.Logger("rcmgr")
2021-12-30 17:33:14 +08:00
type resourceManager struct {
2021-12-23 23:46:08 +08:00
limits Limiter
2022-02-12 00:24:53 +08:00
trace *trace
metrics *metrics
2022-01-15 19:36:28 +08:00
2021-12-30 17:33:14 +08:00
system *systemScope
transient *transientScope
2021-12-23 23:46:08 +08:00
2021-12-30 17:40:09 +08:00
cancelCtx context.Context
cancel func()
wg sync.WaitGroup
2021-12-23 23:46:08 +08:00
mx sync.Mutex
2021-12-30 17:33:14 +08:00
svc map[string]*serviceScope
proto map[protocol.ID]*protocolScope
peer map[peer.ID]*peerScope
2022-01-15 19:36:28 +08:00
stickyProto map[protocol.ID]struct{}
stickyPeer map[peer.ID]struct{}
2022-01-15 19:36:28 +08:00
connId, streamId int64
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
var _ network.ResourceManager = (*resourceManager)(nil)
2021-12-23 23:46:08 +08:00
2021-12-30 17:33:14 +08:00
type systemScope struct {
*resourceScope
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
var _ network.ResourceScope = (*systemScope)(nil)
2021-12-23 21:28:14 +08:00
2021-12-30 17:33:14 +08:00
type transientScope struct {
*resourceScope
2021-12-23 21:28:14 +08:00
2021-12-30 17:33:14 +08:00
system *systemScope
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
var _ network.ResourceScope = (*transientScope)(nil)
2021-12-23 21:28:14 +08:00
2021-12-30 17:33:14 +08:00
type serviceScope struct {
*resourceScope
2021-12-23 21:28:14 +08:00
2022-06-03 19:42:58 +08:00
service string
rcmgr *resourceManager
peers map[peer.ID]*resourceScope
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
var _ network.ServiceScope = (*serviceScope)(nil)
2021-12-23 21:28:14 +08:00
2021-12-30 17:33:14 +08:00
type protocolScope struct {
*resourceScope
2021-12-23 21:28:14 +08:00
proto protocol.ID
rcmgr *resourceManager
peers map[peer.ID]*resourceScope
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
var _ network.ProtocolScope = (*protocolScope)(nil)
2021-12-23 21:28:14 +08:00
2021-12-30 17:33:14 +08:00
type peerScope struct {
*resourceScope
2021-12-23 21:28:14 +08:00
2021-12-26 19:14:59 +08:00
peer peer.ID
2021-12-30 17:33:14 +08:00
rcmgr *resourceManager
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
var _ network.PeerScope = (*peerScope)(nil)
2021-12-23 21:28:14 +08:00
2021-12-30 17:33:14 +08:00
type connectionScope struct {
*resourceScope
2021-12-23 21:28:14 +08:00
2021-12-26 19:14:59 +08:00
dir network.Direction
usefd bool
2021-12-30 17:33:14 +08:00
rcmgr *resourceManager
peer *peerScope
2021-12-23 21:28:14 +08:00
}
2021-12-31 20:31:38 +08:00
var _ network.ConnScope = (*connectionScope)(nil)
var _ network.ConnManagementScope = (*connectionScope)(nil)
2021-12-23 21:28:14 +08:00
2021-12-30 17:33:14 +08:00
type streamScope struct {
*resourceScope
2021-12-23 21:28:14 +08:00
2021-12-26 19:14:59 +08:00
dir network.Direction
2021-12-30 17:33:14 +08:00
rcmgr *resourceManager
peer *peerScope
svc *serviceScope
proto *protocolScope
peerProtoScope *resourceScope
peerSvcScope *resourceScope
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
var _ network.StreamScope = (*streamScope)(nil)
var _ network.StreamManagementScope = (*streamScope)(nil)
2021-12-23 21:28:14 +08:00
type Option func(*resourceManager) error
func NewResourceManager(limits Limiter, opts ...Option) (network.ResourceManager, error) {
2021-12-30 17:33:14 +08:00
r := &resourceManager{
limits: limits,
2021-12-30 17:33:14 +08:00
svc: make(map[string]*serviceScope),
proto: make(map[protocol.ID]*protocolScope),
peer: make(map[peer.ID]*peerScope),
}
for _, opt := range opts {
if err := opt(r); err != nil {
return nil, err
}
}
2022-01-15 19:36:28 +08:00
if err := r.trace.Start(limits); err != nil {
return nil, err
}
r.system = newSystemScope(limits.GetSystemLimits(), r)
2021-12-24 18:01:53 +08:00
r.system.IncRef()
2022-01-15 19:36:28 +08:00
r.transient = newTransientScope(limits.GetTransientLimits(), r)
2021-12-24 18:01:53 +08:00
r.transient.IncRef()
r.cancelCtx, r.cancel = context.WithCancel(context.Background())
r.wg.Add(1)
go r.background()
return r, nil
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) ViewSystem(f func(network.ResourceScope) error) error {
2021-12-24 00:29:41 +08:00
return f(r.system)
2021-12-23 23:46:08 +08:00
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) ViewTransient(f func(network.ResourceScope) error) error {
2021-12-24 00:29:41 +08:00
return f(r.transient)
2021-12-23 23:46:08 +08:00
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) ViewService(srv string, f func(network.ServiceScope) error) error {
2021-12-24 18:01:53 +08:00
s := r.getServiceScope(srv)
defer s.DecRef()
return f(s)
2021-12-23 23:46:08 +08:00
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) ViewProtocol(proto protocol.ID, f func(network.ProtocolScope) error) error {
2021-12-24 00:39:25 +08:00
s := r.getProtocolScope(proto)
2021-12-24 00:29:41 +08:00
defer s.DecRef()
return f(s)
2021-12-23 23:46:08 +08:00
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) ViewPeer(p peer.ID, f func(network.PeerScope) error) error {
2021-12-24 00:29:41 +08:00
s := r.getPeerScope(p)
defer s.DecRef()
return f(s)
2021-12-23 23:46:08 +08:00
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) getServiceScope(svc string) *serviceScope {
2021-12-23 23:46:08 +08:00
r.mx.Lock()
defer r.mx.Unlock()
s, ok := r.svc[svc]
2021-12-23 23:46:08 +08:00
if !ok {
s = newServiceScope(svc, r.limits.GetServiceLimits(svc), r)
r.svc[svc] = s
2021-12-23 23:46:08 +08:00
}
2021-12-24 18:01:53 +08:00
s.IncRef()
2021-12-23 23:46:08 +08:00
return s
2021-12-23 21:28:14 +08:00
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) getProtocolScope(proto protocol.ID) *protocolScope {
2021-12-23 23:46:08 +08:00
r.mx.Lock()
defer r.mx.Unlock()
s, ok := r.proto[proto]
2021-12-23 23:46:08 +08:00
if !ok {
s = newProtocolScope(proto, r.limits.GetProtocolLimits(proto), r)
r.proto[proto] = s
2021-12-23 23:46:08 +08:00
}
s.IncRef()
2021-12-23 23:46:08 +08:00
return s
2021-12-23 21:28:14 +08:00
}
func (r *resourceManager) setStickyProtocol(proto protocol.ID) {
r.mx.Lock()
defer r.mx.Unlock()
if r.stickyProto == nil {
r.stickyProto = make(map[protocol.ID]struct{})
}
r.stickyProto[proto] = struct{}{}
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) getPeerScope(p peer.ID) *peerScope {
2021-12-23 23:46:08 +08:00
r.mx.Lock()
defer r.mx.Unlock()
2021-12-23 21:28:14 +08:00
2021-12-23 23:46:08 +08:00
s, ok := r.peer[p]
if !ok {
2021-12-30 17:33:14 +08:00
s = newPeerScope(p, r.limits.GetPeerLimits(p), r)
2021-12-23 23:46:08 +08:00
r.peer[p] = s
}
2021-12-23 21:28:14 +08:00
s.IncRef()
2021-12-23 23:46:08 +08:00
return s
2021-12-23 21:28:14 +08:00
}
func (r *resourceManager) setStickyPeer(p peer.ID) {
r.mx.Lock()
defer r.mx.Unlock()
if r.stickyPeer == nil {
r.stickyPeer = make(map[peer.ID]struct{})
}
r.stickyPeer[p] = struct{}{}
}
2022-01-15 19:36:28 +08:00
func (r *resourceManager) nextConnId() int64 {
r.mx.Lock()
defer r.mx.Unlock()
r.connId++
return r.connId
}
func (r *resourceManager) nextStreamId() int64 {
r.mx.Lock()
defer r.mx.Unlock()
r.streamId++
return r.streamId
}
2021-12-31 20:31:38 +08:00
func (r *resourceManager) OpenConnection(dir network.Direction, usefd bool) (network.ConnManagementScope, error) {
2021-12-30 17:33:14 +08:00
conn := newConnectionScope(dir, usefd, r.limits.GetConnLimits(), r)
2021-12-23 21:28:14 +08:00
2021-12-30 01:21:19 +08:00
if err := conn.AddConn(dir, usefd); err != nil {
2021-12-24 18:01:53 +08:00
conn.Done()
2022-02-12 19:52:47 +08:00
r.metrics.BlockConn(dir, usefd)
2021-12-23 21:28:14 +08:00
return nil, err
}
2022-02-14 23:20:12 +08:00
r.metrics.AllowConn(dir, usefd)
2021-12-23 21:28:14 +08:00
return conn, nil
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) OpenStream(p peer.ID, dir network.Direction) (network.StreamManagementScope, error) {
peer := r.getPeerScope(p)
2022-01-15 19:36:28 +08:00
stream := newStreamScope(dir, r.limits.GetStreamLimits(p), peer, r)
2022-01-14 19:44:32 +08:00
peer.DecRef() // we have the reference in edges
err := stream.AddStream(dir)
if err != nil {
2021-12-24 18:01:53 +08:00
stream.Done()
2022-02-12 19:52:47 +08:00
r.metrics.BlockStream(p, dir)
return nil, err
}
2022-02-14 23:20:12 +08:00
r.metrics.AllowStream(p, dir)
return stream, nil
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) Close() error {
r.cancel()
r.wg.Wait()
2022-01-15 19:36:28 +08:00
r.trace.Close()
2021-12-23 23:46:08 +08:00
return nil
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) background() {
2021-12-28 22:08:07 +08:00
defer r.wg.Done()
// periodically garbage collects unused peer and protocol scopes
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
for {
select {
case <-ticker.C:
r.gc()
case <-r.cancelCtx.Done():
return
}
}
}
2021-12-30 17:33:14 +08:00
func (r *resourceManager) gc() {
r.mx.Lock()
defer r.mx.Unlock()
for proto, s := range r.proto {
_, sticky := r.stickyProto[proto]
if sticky {
continue
}
if s.IsUnused() {
2021-12-28 22:08:07 +08:00
s.Done()
delete(r.proto, proto)
}
}
var deadPeers []peer.ID
for p, s := range r.peer {
_, sticky := r.stickyPeer[p]
if sticky {
continue
}
if s.IsUnused() {
2021-12-28 22:08:07 +08:00
s.Done()
delete(r.peer, p)
deadPeers = append(deadPeers, p)
}
}
for _, s := range r.svc {
s.Lock()
for _, p := range deadPeers {
2022-01-09 04:21:33 +08:00
ps, ok := s.peers[p]
if ok {
ps.Done()
delete(s.peers, p)
}
}
s.Unlock()
}
for _, s := range r.proto {
s.Lock()
for _, p := range deadPeers {
ps, ok := s.peers[p]
if ok {
ps.Done()
delete(s.peers, p)
}
}
s.Unlock()
}
}
2022-01-15 19:36:28 +08:00
func newSystemScope(limit Limit, rcmgr *resourceManager) *systemScope {
2021-12-30 17:33:14 +08:00
return &systemScope{
resourceScope: newResourceScope(limit, nil, scopeName{IsSystem: true}, rcmgr.trace, rcmgr.metrics),
2021-12-23 21:28:14 +08:00
}
}
2022-01-15 19:36:28 +08:00
func newTransientScope(limit Limit, rcmgr *resourceManager) *transientScope {
2021-12-30 17:33:14 +08:00
return &transientScope{
2022-02-12 19:59:46 +08:00
resourceScope: newResourceScope(limit,
[]*resourceScope{rcmgr.system.resourceScope},
scopeName{IsTransient: true}, rcmgr.trace, rcmgr.metrics),
2022-02-12 19:59:46 +08:00
system: rcmgr.system,
2021-12-23 21:28:14 +08:00
}
}
2022-06-03 19:42:58 +08:00
func newServiceScope(service string, limit Limit, rcmgr *resourceManager) *serviceScope {
2021-12-30 17:33:14 +08:00
return &serviceScope{
2022-02-12 19:59:46 +08:00
resourceScope: newResourceScope(limit,
[]*resourceScope{rcmgr.system.resourceScope},
scopeName{Service: service}, rcmgr.trace, rcmgr.metrics),
2022-06-03 19:42:58 +08:00
service: service,
rcmgr: rcmgr,
2021-12-23 21:28:14 +08:00
}
}
func newProtocolScope(proto protocol.ID, limit Limit, rcmgr *resourceManager) *protocolScope {
2021-12-30 17:33:14 +08:00
return &protocolScope{
2022-02-12 19:59:46 +08:00
resourceScope: newResourceScope(limit,
[]*resourceScope{rcmgr.system.resourceScope},
scopeName{Protocol: proto}, rcmgr.trace, rcmgr.metrics),
2022-02-12 19:59:46 +08:00
proto: proto,
rcmgr: rcmgr,
2021-12-23 21:28:14 +08:00
}
}
2021-12-30 17:33:14 +08:00
func newPeerScope(p peer.ID, limit Limit, rcmgr *resourceManager) *peerScope {
return &peerScope{
2022-02-12 19:59:46 +08:00
resourceScope: newResourceScope(limit,
[]*resourceScope{rcmgr.system.resourceScope},
scopeName{Peer: p}, rcmgr.trace, rcmgr.metrics),
2022-02-12 19:59:46 +08:00
peer: p,
rcmgr: rcmgr,
2021-12-23 21:28:14 +08:00
}
}
2021-12-30 17:33:14 +08:00
func newConnectionScope(dir network.Direction, usefd bool, limit Limit, rcmgr *resourceManager) *connectionScope {
return &connectionScope{
2022-02-12 19:59:46 +08:00
resourceScope: newResourceScope(limit,
[]*resourceScope{rcmgr.transient.resourceScope, rcmgr.system.resourceScope},
scopeName{ConnID: rcmgr.nextConnId()}, rcmgr.trace, rcmgr.metrics),
2022-02-12 19:59:46 +08:00
dir: dir,
usefd: usefd,
rcmgr: rcmgr,
2021-12-23 21:28:14 +08:00
}
}
2022-01-15 19:36:28 +08:00
func newStreamScope(dir network.Direction, limit Limit, peer *peerScope, rcmgr *resourceManager) *streamScope {
2021-12-30 17:33:14 +08:00
return &streamScope{
2022-02-12 19:59:46 +08:00
resourceScope: newResourceScope(limit,
[]*resourceScope{peer.resourceScope, rcmgr.transient.resourceScope, rcmgr.system.resourceScope},
scopeName{StreamID: rcmgr.nextStreamId()}, rcmgr.trace, rcmgr.metrics),
2022-02-12 19:59:46 +08:00
dir: dir,
rcmgr: peer.rcmgr,
peer: peer,
2021-12-23 21:28:14 +08:00
}
}
2021-12-30 17:33:14 +08:00
func (s *serviceScope) Name() string {
2022-06-03 19:42:58 +08:00
return s.service
2021-12-23 21:28:14 +08:00
}
func (s *serviceScope) getPeerScope(p peer.ID) *resourceScope {
s.Lock()
defer s.Unlock()
ps, ok := s.peers[p]
if ok {
ps.IncRef()
return ps
}
2022-06-03 19:42:58 +08:00
l := s.rcmgr.limits.GetServicePeerLimits(s.service)
if s.peers == nil {
s.peers = make(map[peer.ID]*resourceScope)
}
sn := s.name
sn.Peer = p
ps = newResourceScope(l, nil, sn, s.rcmgr.trace, s.rcmgr.metrics)
s.peers[p] = ps
ps.IncRef()
return ps
}
2021-12-30 17:33:14 +08:00
func (s *protocolScope) Protocol() protocol.ID {
2021-12-23 21:28:14 +08:00
return s.proto
}
func (s *protocolScope) getPeerScope(p peer.ID) *resourceScope {
s.Lock()
defer s.Unlock()
ps, ok := s.peers[p]
if ok {
ps.IncRef()
return ps
}
l := s.rcmgr.limits.GetProtocolPeerLimits(s.proto)
if s.peers == nil {
s.peers = make(map[peer.ID]*resourceScope)
}
sn := s.name
sn.Peer = p
ps = newResourceScope(l, nil, sn, s.rcmgr.trace, s.rcmgr.metrics)
s.peers[p] = ps
ps.IncRef()
return ps
}
2021-12-30 17:33:14 +08:00
func (s *peerScope) Peer() peer.ID {
2021-12-23 21:28:14 +08:00
return s.peer
}
2021-12-30 17:33:14 +08:00
func (s *connectionScope) PeerScope() network.PeerScope {
2021-12-23 21:28:14 +08:00
s.Lock()
defer s.Unlock()
2022-02-03 14:51:08 +08:00
// avoid nil is not nil footgun; go....
if s.peer == nil {
return nil
}
2021-12-23 21:28:14 +08:00
return s.peer
}
2021-12-30 17:33:14 +08:00
func (s *connectionScope) SetPeer(p peer.ID) error {
2021-12-23 21:28:14 +08:00
s.Lock()
defer s.Unlock()
if s.peer != nil {
return fmt.Errorf("connection scope already attached to a peer")
}
s.peer = s.rcmgr.getPeerScope(p)
// juggle resources from transient scope to peer scope
2021-12-30 17:33:14 +08:00
stat := s.resourceScope.rc.stat()
if err := s.peer.ReserveForChild(stat); err != nil {
2021-12-24 18:01:53 +08:00
s.peer.DecRef()
2021-12-26 19:14:59 +08:00
s.peer = nil
2022-02-12 19:52:47 +08:00
s.rcmgr.metrics.BlockPeer(p)
2021-12-23 21:28:14 +08:00
return err
}
s.rcmgr.transient.ReleaseForChild(stat)
2022-01-14 19:44:32 +08:00
s.rcmgr.transient.DecRef() // removed from edges
2021-12-23 21:28:14 +08:00
2022-01-14 19:44:32 +08:00
// update edges
edges := []*resourceScope{
2021-12-30 17:33:14 +08:00
s.peer.resourceScope,
s.rcmgr.system.resourceScope,
2021-12-23 21:28:14 +08:00
}
2022-01-14 19:44:32 +08:00
s.resourceScope.edges = edges
2021-12-23 21:28:14 +08:00
2022-02-14 23:20:12 +08:00
s.rcmgr.metrics.AllowPeer(p)
2021-12-23 21:28:14 +08:00
return nil
}
2021-12-30 17:33:14 +08:00
func (s *streamScope) ProtocolScope() network.ProtocolScope {
2021-12-23 21:28:14 +08:00
s.Lock()
defer s.Unlock()
2022-02-03 14:51:08 +08:00
// avoid nil is not nil footgun; go....
if s.proto == nil {
return nil
}
2021-12-23 21:28:14 +08:00
return s.proto
}
2021-12-30 17:33:14 +08:00
func (s *streamScope) SetProtocol(proto protocol.ID) error {
2021-12-23 21:28:14 +08:00
s.Lock()
defer s.Unlock()
if s.proto != nil {
return fmt.Errorf("stream scope already attached to a protocol")
}
s.proto = s.rcmgr.getProtocolScope(proto)
// juggle resources from transient scope to protocol scope
2021-12-30 17:33:14 +08:00
stat := s.resourceScope.rc.stat()
if err := s.proto.ReserveForChild(stat); err != nil {
2021-12-28 22:08:07 +08:00
s.proto.DecRef()
s.proto = nil
2022-02-12 19:52:47 +08:00
s.rcmgr.metrics.BlockProtocol(proto)
2021-12-23 21:28:14 +08:00
return err
}
s.peerProtoScope = s.proto.getPeerScope(s.peer.peer)
if err := s.peerProtoScope.ReserveForChild(stat); err != nil {
s.proto.ReleaseForChild(stat)
s.proto.DecRef()
s.proto = nil
s.peerProtoScope.DecRef()
s.peerProtoScope = nil
2022-02-12 19:52:47 +08:00
s.rcmgr.metrics.BlockProtocolPeer(proto, s.peer.peer)
return err
}
s.rcmgr.transient.ReleaseForChild(stat)
2022-01-14 19:44:32 +08:00
s.rcmgr.transient.DecRef() // removed from edges
2021-12-23 21:28:14 +08:00
2022-01-14 19:44:32 +08:00
// update edges
edges := []*resourceScope{
2021-12-30 17:33:14 +08:00
s.peer.resourceScope,
s.peerProtoScope,
2021-12-30 17:33:14 +08:00
s.proto.resourceScope,
s.rcmgr.system.resourceScope,
2021-12-23 21:28:14 +08:00
}
2022-01-14 19:44:32 +08:00
s.resourceScope.edges = edges
2021-12-23 21:28:14 +08:00
2022-02-14 23:20:12 +08:00
s.rcmgr.metrics.AllowProtocol(proto)
2021-12-23 21:28:14 +08:00
return nil
}
2021-12-30 17:33:14 +08:00
func (s *streamScope) ServiceScope() network.ServiceScope {
2021-12-23 21:28:14 +08:00
s.Lock()
defer s.Unlock()
2022-02-03 14:51:08 +08:00
// avoid nil is not nil footgun; go....
if s.svc == nil {
return nil
}
2021-12-23 21:28:14 +08:00
return s.svc
}
2021-12-30 17:33:14 +08:00
func (s *streamScope) SetService(svc string) error {
2021-12-23 21:28:14 +08:00
s.Lock()
defer s.Unlock()
if s.svc != nil {
return fmt.Errorf("stream scope already attached to a service")
}
if s.proto == nil {
return fmt.Errorf("stream scope not attached to a protocol")
}
2021-12-23 21:28:14 +08:00
s.svc = s.rcmgr.getServiceScope(svc)
// reserve resources in service
stat := s.resourceScope.rc.stat()
if err := s.svc.ReserveForChild(stat); err != nil {
2021-12-24 18:01:53 +08:00
s.svc.DecRef()
s.svc = nil
2022-02-12 19:52:47 +08:00
s.rcmgr.metrics.BlockService(svc)
2021-12-23 21:28:14 +08:00
return err
}
// get the per peer service scope constraint, if any
s.peerSvcScope = s.svc.getPeerScope(s.peer.peer)
if err := s.peerSvcScope.ReserveForChild(stat); err != nil {
s.svc.ReleaseForChild(stat)
s.svc.DecRef()
s.svc = nil
s.peerSvcScope.DecRef()
s.peerSvcScope = nil
2022-02-12 19:52:47 +08:00
s.rcmgr.metrics.BlockServicePeer(svc, s.peer.peer)
return err
}
2022-01-14 19:44:32 +08:00
// update edges
edges := []*resourceScope{
2021-12-30 17:33:14 +08:00
s.peer.resourceScope,
s.peerProtoScope,
s.peerSvcScope,
s.proto.resourceScope,
s.svc.resourceScope,
s.rcmgr.system.resourceScope,
2021-12-23 21:28:14 +08:00
}
2022-01-14 19:44:32 +08:00
s.resourceScope.edges = edges
2021-12-23 21:28:14 +08:00
2022-02-14 23:20:12 +08:00
s.rcmgr.metrics.AllowService(svc)
2021-12-23 21:28:14 +08:00
return nil
}
2021-12-30 17:33:14 +08:00
func (s *streamScope) PeerScope() network.PeerScope {
2021-12-23 21:28:14 +08:00
s.Lock()
defer s.Unlock()
2022-02-03 14:51:08 +08:00
// avoid nil is not nil footgun; go....
if s.peer == nil {
return nil
}
2021-12-23 21:28:14 +08:00
return s.peer
}