feat: improve operations diagnostics and channel management
This commit is contained in:
@@ -13,10 +13,12 @@ import (
|
||||
)
|
||||
|
||||
type authRequest struct {
|
||||
Account string `json:"account"`
|
||||
AuthSource string `json:"authSource"`
|
||||
Timestamp uint32 `json:"timestamp"`
|
||||
RemoteIP string `json:"remoteIp,omitempty"`
|
||||
Account string `json:"account"`
|
||||
AuthSource string `json:"authSource"`
|
||||
Timestamp uint32 `json:"timestamp"`
|
||||
RemoteIP string `json:"remoteIp,omitempty"`
|
||||
Version string `json:"version"`
|
||||
RequestedVersion uint8 `json:"requestedVersion"`
|
||||
}
|
||||
|
||||
type authResponse struct {
|
||||
@@ -42,7 +44,7 @@ func (s Server) handleLogin(response *cmpp.Response, packet *cmpp.Packet, logger
|
||||
setInboundConnectResponse(response.Packer, cmpp.ErrnoConnVerTooHigh, req.AuthSrc, "", cmpp.V30)
|
||||
return false, cmpp.ConnRspStatusErrMap[cmpp.ErrnoConnVerTooHigh]
|
||||
}
|
||||
auth, err := s.authenticate(packet.Conn.Conn.RemoteAddr(), account, req.AuthSrc, req.Timestamp)
|
||||
auth, err := s.authenticate(packet.Conn.Conn.RemoteAddr(), account, req.AuthSrc, req.Timestamp, req.Version)
|
||||
if err != nil {
|
||||
logger.Printf("cmpp inbound auth failed account=%s remote=%s err=%v", account, packet.Conn.Conn.RemoteAddr(), err)
|
||||
setInboundConnectResponse(response.Packer, cmpp.ErrnoConnAuthFailed, req.AuthSrc, "", req.Version)
|
||||
@@ -114,12 +116,14 @@ func cmppVersionName(version cmpp.Type) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (s Server) authenticate(remote net.Addr, account string, authSource string, timestamp uint32) (authResponse, error) {
|
||||
func (s Server) authenticate(remote net.Addr, account string, authSource string, timestamp uint32, version cmpp.Type) (authResponse, error) {
|
||||
payload := authRequest{
|
||||
Account: account,
|
||||
AuthSource: base64.StdEncoding.EncodeToString([]byte(authSource)),
|
||||
Timestamp: timestamp,
|
||||
RemoteIP: remoteIP(remote),
|
||||
Account: account,
|
||||
AuthSource: base64.StdEncoding.EncodeToString([]byte(authSource)),
|
||||
Timestamp: timestamp,
|
||||
RemoteIP: remoteIP(remote),
|
||||
Version: cmppVersionName(version),
|
||||
RequestedVersion: uint8(version),
|
||||
}
|
||||
var result authResponse
|
||||
err := s.post(context.Background(), "/gateway/events/inbound/authenticate", payload, &result)
|
||||
|
||||
@@ -228,7 +228,7 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("expected downstream acknowledgement callback")
|
||||
}
|
||||
if gotAuth.Account != account || gotAuth.AuthSource == "" || gotAuth.RemoteIP == "" {
|
||||
if gotAuth.Account != account || gotAuth.AuthSource == "" || gotAuth.RemoteIP == "" || gotAuth.Version != "cmpp30" || gotAuth.RequestedVersion != uint8(cmpp.V30) {
|
||||
t.Fatalf("unexpected auth payload: %+v", gotAuth)
|
||||
}
|
||||
if gotSubmit.Account != account || gotSubmit.PhoneNumber != "13500002696" || gotSubmit.Content != "测试入站" ||
|
||||
|
||||
Reference in New Issue
Block a user