func (r *rpc) Expire() {
	r.Lock()
	defer r.Unlock()
	n := len(r.nodes)
expiration:
	for i := n - 1; i >= 0; i-- {
		e := r.nodes[i]
		if nil == e || e.local {
			continue expiration
		}
		if time.Since(e.timestamp) > parameter.ExpiryInterval {
			delete(r.index, e.fin)
			n--
			if i != n {
				e := r.nodes[n]
				r.nodes[i] = e
				r.index[e.fin] = i
			}
			r.nodes[n] = nil
		}
	}
	r.nodes = r.nodes[:n]  
}
Expire - called in background to expire outdated RPC entries
package rpc
import (
	"bytes"
	"sync"
	"time"
	"github.com/bitmark-inc/bitmarkd/announce/fingerprint"
	"github.com/bitmark-inc/bitmarkd/announce/helper"
	"github.com/bitmark-inc/bitmarkd/announce/parameter"
	"github.com/bitmark-inc/bitmarkd/fault"
	"github.com/bitmark-inc/bitmarkd/util"
)
const (
	addressLimit = 100
	maxNodeCount = 1000
)
type RPC interface {
	Set(fingerprint.Fingerprint, []byte) error
	Add([]byte, []byte, uint64) bool
	Expire()
	IsInitialised() bool
	Fetch(start uint64, count int) ([]Entry, uint64, error)
	Self() []byte
	ID() fingerprint.Fingerprint
}
type Entry struct {
	Fingerprint fingerprint.Fingerprint `json:"fingerprint"`
	Connections []*util.Connection      `json:"connections"`
}
type node struct {
	address   util.PackedConnection    
	fin       fingerprint.Fingerprint  
	timestamp time.Time                
	local     bool                     
}
type rpc struct {
	sync.RWMutex
	fin         fingerprint.Fingerprint
	initialised bool
	nodes       []*node
	index       map[fingerprint.Fingerprint]int
	self        []byte
}
func (r *rpc) Set(fin fingerprint.Fingerprint, rpcs []byte) error {
	r.Lock()
	defer r.Unlock()
	if r.initialised {
		return fault.AlreadyInitialised
	}
	r.fin = fin
	r.self = rpcs
	r.initialised = true
	r.add(fin, rpcs, uint64(time.Now().Unix()), true)
	return nil
}
func (r *rpc) Add(f []byte, listeners []byte, timestamp uint64) bool {
	var fp fingerprint.Fingerprint
	if len(fp) != len(f) || len(listeners) > addressLimit {
		return false
	}
	copy(fp[:], f)
	r.Lock()
	rc := r.add(fp, listeners, timestamp, false)
	r.Unlock()
	return rc
}
func (r *rpc) add(fin fingerprint.Fingerprint, listeners []byte, timestamp uint64, local bool) bool {
	i, ok := r.index[fin]
	if !ok {
		ts := helper.ResetFutureTimestampToNow(timestamp)
		if helper.IsExpiredAfterDuration(ts, parameter.ExpiryInterval) {
			return false
		}
		e := &node{
			address:   listeners,
			fin:       fin,
			timestamp: ts,
			local:     local,
		}
		n := len(r.nodes)
		r.nodes = append(r.nodes, e)
		r.index[fin] = n
		return true
	}
	e := r.nodes[i]
	if !bytes.Equal(e.address, listeners) {
		e.address = listeners
	}
	rc := time.Since(e.timestamp) > parameter.RebroadcastInterval
	e.timestamp = time.Now()
	return rc
}