func (l *link) setRate(bits int64, delta time.Duration) {
	rate := float64(bits) / float64(delta.Nanoseconds())
	if l.rate == 0 {
		l.rate = rate * 1e9
	} else {
		l.rate = 0.8*l.rate + 0.2*(rate*1e9)
	}
}
setRate sets the bits per second rate as a float64
package mucp
import (
	"bytes"
	"errors"
	"io"
	"sync"
	"time"
	"github.com/google/uuid"
	"github.com/micro/micro/v3/service/logger"
	"github.com/micro/micro/v3/service/network/transport"
)
type link struct {
	transport.Socket
	transport transport.Transport
	sync.RWMutex
	closed chan bool
	metric chan *metric
	state chan *packet
	sendQueue chan *packet
	recvQueue chan *packet
	id string
	loopback bool
	connected bool
	lastKeepAlive time.Time
	channels map[string]time.Time
	length int64
	rate float64
	errCount int
}
type packet struct {
	message *transport.Message
	status chan error
	err error
}
type metric struct {
	data int
	duration time.Duration
	status error
}
var (
	linkRequest = []byte{0, 0, 0, 0}
	linkResponse = []byte{1, 1, 1, 1}
	ErrLinkConnectTimeout = errors.New("link connect timeout")
)
func newLink(s transport.Socket) *link {
	l := &link{
		Socket:        s,
		id:            uuid.New().String(),
		lastKeepAlive: time.Now(),
		closed:        make(chan bool),
		channels:      make(map[string]time.Time),
		state:         make(chan *packet, 64),
		sendQueue:     make(chan *packet, 128),
		recvQueue:     make(chan *packet, 128),
		metric:        make(chan *metric, 128),
	}
	go l.process()
	go l.manage()
	return l
}