Added BiRPCClient to analyzers

This commit is contained in:
Trial97
2021-07-08 12:33:55 +03:00
committed by Dan Christian Bogos
parent d86fe1592b
commit 8fed2775dd
3 changed files with 47 additions and 2 deletions

View File

@@ -43,9 +43,46 @@ type AnalyzerConnector struct {
to string
}
func (c *AnalyzerConnector) Call(serviceMethod string, args interface{}, reply interface{}) (err error) {
func (c *AnalyzerConnector) Call(serviceMethod string, args, reply interface{}) (err error) {
sTime := time.Now()
err = c.conn.Call(serviceMethod, args, reply)
go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now())
return
}
func (aS *AnalyzerService) NewAnalyzerBiRPCConnector(sc rpcclient.BiRPCConector, enc, from, to string) rpcclient.BiRPCConector {
return &AnalyzerBiRPCConnector{
conn: sc,
aS: aS,
enc: enc,
from: from,
to: to,
}
}
type AnalyzerBiRPCConnector struct {
conn rpcclient.BiRPCConector
aS *AnalyzerService
enc string
from string
to string
}
func (c *AnalyzerBiRPCConnector) Call(serviceMethod string, args, reply interface{}) (err error) {
sTime := time.Now()
err = c.conn.Call(serviceMethod, args, reply)
go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now())
return
}
func (c *AnalyzerBiRPCConnector) CallBiRPC(cl rpcclient.ClientConnector, serviceMethod string, args, reply interface{}) (err error) {
sTime := time.Now()
err = c.conn.CallBiRPC(cl, serviceMethod, args, reply)
go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now())
return
}
func (c *AnalyzerBiRPCConnector) Handlers() map[string]interface{} {
return c.conn.Handlers()
}

View File

@@ -154,3 +154,11 @@ func (anz *AnalyzerService) GetInternalCodec(c rpcclient.ClientConnector, to str
}
return anz.anz.NewAnalyzerConnector(c, utils.MetaInternal, utils.EmptyString, to)
}
// GetInternalCodec returns the connection wrapped in analyzer connector
func (anz *AnalyzerService) GetInternalBiRPCCodec(c rpcclient.BiRPCConector, to string) rpcclient.BiRPCConector {
if !anz.IsRunning() {
return c
}
return anz.anz.NewAnalyzerBiRPCConnector(c, rpcclient.BiRPCInternal, utils.EmptyString, to)
}

View File

@@ -94,7 +94,7 @@ func (smg *SessionService) Start() (err error) {
smg.stopChan = make(chan struct{})
go smg.sm.ListenAndServe(smg.stopChan)
// Pass internal connection via BiRPCClient
smg.connChan <- smg.anz.GetInternalCodec(smg.sm, utils.SessionS)
smg.connChan <- smg.anz.GetInternalBiRPCCodec(smg.sm, utils.SessionS)
// Register RPC handler
smg.rpc = v1.NewSMGenericV1(smg.sm, smg.caps)