|
@@ -8,8 +8,6 @@ import (
|
|
|
"net"
|
|
|
"sync"
|
|
|
"time"
|
|
|
-
|
|
|
- "git.nspix.com/golang/micro/stats"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -19,9 +17,6 @@ const (
|
|
|
var (
|
|
|
ErrShortFeature = errors.New("short feature")
|
|
|
ErrFeatureExists = errors.New("feature already exists")
|
|
|
-
|
|
|
- requestCounter = stats.NewCounter("GatewayRequestCount", "Number of gateway request")
|
|
|
- requestDropCounter = stats.NewCountersWithSingleLabel("GatewayRequestDropedCount", "Number of dropped by unusual request", "Reason")
|
|
|
)
|
|
|
|
|
|
type (
|
|
@@ -79,46 +74,26 @@ func (g *Gateway) process(conn net.Conn) {
|
|
|
var (
|
|
|
n int
|
|
|
err error
|
|
|
- missing uint8
|
|
|
feature = make([]byte, MinFeatureLength)
|
|
|
)
|
|
|
- if g.enableStats {
|
|
|
- requestCounter.Add(1)
|
|
|
- }
|
|
|
//set deadline
|
|
|
if err = conn.SetReadDeadline(time.Now().Add(time.Second)); err != nil {
|
|
|
- if g.enableStats {
|
|
|
- requestDropCounter.Add("ERROR", 1)
|
|
|
- }
|
|
|
return
|
|
|
}
|
|
|
if n, err = io.ReadFull(conn, feature); err != nil {
|
|
|
- if g.enableStats {
|
|
|
- requestDropCounter.Add("EOF", 1)
|
|
|
- }
|
|
|
_ = conn.Close()
|
|
|
return
|
|
|
}
|
|
|
//reset deadline
|
|
|
if err = conn.SetReadDeadline(time.Time{}); err != nil {
|
|
|
- if g.enableStats {
|
|
|
- requestDropCounter.Add("ERROR", 1)
|
|
|
- }
|
|
|
return
|
|
|
}
|
|
|
- missing = 1
|
|
|
for _, l := range g.listeners {
|
|
|
- if bytes.Equal(feature[:n], l.feature[:n]) {
|
|
|
+ if bytes.Compare(feature[:n], l.feature[:n]) == 0 {
|
|
|
l.l.Receive(wrapConn(conn, feature[:n]))
|
|
|
- missing = 0
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- if missing == 1 {
|
|
|
- if g.enableStats {
|
|
|
- requestDropCounter.Add("MISSING", 1)
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
func (g *Gateway) worker(ctx context.Context) {
|