Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjie199234 committed Feb 29, 2024
1 parent 3ceef3f commit 139f297
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *CrpcClient) start(server *ServerForPick, reconnect bool) {
}
}

func (c *CrpcClient) verifyfunc(ctx context.Context, peerVerifyData []byte) ([]byte, bool) {
func (c *CrpcClient) verifyfunc(ctx context.Context, peerVerifyData []byte, p *stream.Peer) ([]byte, bool) {
//verify success
return nil, true
}
Expand Down
2 changes: 1 addition & 1 deletion crpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (s *CrpcServer) insidehandler(path string, handlers ...OutsideHandler) func
}

// return false will close the connection
func (s *CrpcServer) verifyfunc(ctx context.Context, peerVerifyData []byte) ([]byte, bool) {
func (s *CrpcServer) verifyfunc(ctx context.Context, peerVerifyData []byte, p *stream.Peer) ([]byte, bool) {
if s.stop.Closing() {
//self closing
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion stream/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// server's response will write back to the client for client to verify the server
// client's response is useless and it will be dropped,you can just return nil
// Warning!!!Don't reuse the data in 'peerVerifyData',it will change when this function return,if you want to use it,copy it first
type HandleVerifyFunc func(ctx context.Context, peerVerifyData []byte) (response []byte, success bool)
type HandleVerifyFunc func(ctx context.Context, peerVerifyData []byte, p *Peer) (response []byte, success bool)

// This is a notice func after verify each other success
// success = true means online success
Expand Down
4 changes: 2 additions & 2 deletions stream/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (this *Instance) StartServer(listenaddr string, tlsc *tls.Config) error {
p := newPeer(this.c.TcpC.MaxMsgLen, _PEER_CLIENT, "")
conn, e := tmplistener.AcceptTCP()
if e != nil {
if ee, ok := e.(net.Error); ok && ee.Temporary() {
if ee, ok := e.(interface{ Temporary() bool }); ok && ee.Temporary() {
log.Error(nil, "[Stream.StartServer] accept tcp connection failed", log.CError(e))
continue
}
Expand Down Expand Up @@ -365,7 +365,7 @@ func (this *Instance) verifypeer(ctx context.Context, p *Peer) []byte {
p.recvidlestart = p.lastactive
p.sendidlestart = p.lastactive
p.peerMaxMsgLen = senderMaxRecvMsgLen
r, success := this.c.VerifyFunc(ctx, data[4:])
r, success := this.c.VerifyFunc(ctx, data[4:], p)
if !success {
if p.peertype == _PEER_CLIENT {
log.Error(nil, "[Stream.verifypeer] verify client failed", log.String("cip", p.c.RemoteAddr().String()))
Expand Down
2 changes: 1 addition & 1 deletion stream/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Test_Server(t *testing.T) {
}()
http.ListenAndServe(":8080", nil)
}
func serverhandleVerify(ctx context.Context, peerVerifyData []byte) ([]byte, bool) {
func serverhandleVerify(ctx context.Context, peerVerifyData []byte, p *Peer) ([]byte, bool) {
if !bytes.Equal([]byte{'t', 'e', 's', 't', 'c'}, peerVerifyData) {
fmt.Println("verify error")
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion stream/tcpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_Tcpclient(t *testing.T) {
}()
http.ListenAndServe(":8081", nil)
}
func tcpclienthandleVerify(ctx context.Context, peerVerifyData []byte) ([]byte, bool) {
func tcpclienthandleVerify(ctx context.Context, peerVerifyData []byte, p *Peer) ([]byte, bool) {
if !bytes.Equal([]byte{'t', 'e', 's', 't'}, peerVerifyData) {
fmt.Println("verify error")
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion stream/wsclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_Wsclient(t *testing.T) {
}()
http.ListenAndServe(":8082", nil)
}
func wsclienthandleVerify(ctx context.Context, peerVerifyData []byte) ([]byte, bool) {
func wsclienthandleVerify(ctx context.Context, peerVerifyData []byte, p *Peer) ([]byte, bool) {
if !bytes.Equal([]byte{'t', 'e', 's', 't'}, peerVerifyData) {
fmt.Println("verify error")
return nil, false
Expand Down

0 comments on commit 139f297

Please sign in to comment.