rpc: logging for bytestream listener

This commit is contained in:
Christian Schwarz 2017-05-12 20:26:48 +02:00
parent 53b3a940ec
commit feabf1abcd
2 changed files with 7 additions and 2 deletions

View File

@ -117,7 +117,7 @@ func doSink(c *cli.Context) (err error) {
PullMapping: findMapping(conf.PullACLs), PullMapping: findMapping(conf.PullACLs),
} }
if err = rpc.ListenByteStreamRPC(sshByteStream, handler); err != nil { if err = rpc.ListenByteStreamRPC(sshByteStream, handler, sinkLogger); err != nil {
//os.Exit(1) //os.Exit(1)
err = cli.NewExitError(err, 1) err = cli.NewExitError(err, 1)
defaultLog.Printf("listenbytestreamerror: %#v\n", err) defaultLog.Printf("listenbytestreamerror: %#v\n", err)

View File

@ -27,12 +27,17 @@ type RPCHandler interface {
HandleIncrementalTransferRequest(r IncrementalTransferRequest) (io.Reader, error) HandleIncrementalTransferRequest(r IncrementalTransferRequest) (io.Reader, error)
} }
type Logger interface {
Printf(format string, args ...interface{})
}
const ByteStreamRPCProtocolVersion = 1 const ByteStreamRPCProtocolVersion = 1
type ByteStreamRPC struct { type ByteStreamRPC struct {
conn io.ReadWriteCloser conn io.ReadWriteCloser
encoder *json.Encoder encoder *json.Encoder
decoder *json.Decoder decoder *json.Decoder
log Logger
} }
func ConnectByteStreamRPC(conn io.ReadWriteCloser) (RPCRequester, error) { func ConnectByteStreamRPC(conn io.ReadWriteCloser) (RPCRequester, error) {
@ -52,7 +57,7 @@ func ConnectByteStreamRPC(conn io.ReadWriteCloser) (RPCRequester, error) {
return rpc, nil return rpc, nil
} }
func ListenByteStreamRPC(conn io.ReadWriteCloser, handler RPCHandler) error { func ListenByteStreamRPC(conn io.ReadWriteCloser, handler RPCHandler, log Logger) error {
// A request consists of two subsequent JSON objects // A request consists of two subsequent JSON objects
// Object 1: RequestHeader => contains type of Request Body // Object 1: RequestHeader => contains type of Request Body