From 949ccff832a08acc9bb3a0eadb0a60536b4adb47 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 17 Jun 2017 12:51:25 +0200 Subject: pkg/rpctype: from from rpctype --- pkg/rpctype/rpc.go | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ pkg/rpctype/rpctype.go | 78 ++++++++++++++++++++++++++++++++++++++++++++ rpctype/rpc.go | 88 -------------------------------------------------- rpctype/rpctype.go | 78 -------------------------------------------- syz-fuzzer/fuzzer.go | 2 +- syz-hub/hub.go | 2 +- syz-manager/manager.go | 2 +- 7 files changed, 169 insertions(+), 169 deletions(-) create mode 100644 pkg/rpctype/rpc.go create mode 100644 pkg/rpctype/rpctype.go delete mode 100644 rpctype/rpc.go delete mode 100644 rpctype/rpctype.go diff --git a/pkg/rpctype/rpc.go b/pkg/rpctype/rpc.go new file mode 100644 index 000000000..8400b0e95 --- /dev/null +++ b/pkg/rpctype/rpc.go @@ -0,0 +1,88 @@ +// Copyright 2017 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package rpctype + +import ( + "fmt" + "net" + "net/rpc" + "time" + + . "github.com/google/syzkaller/pkg/log" +) + +type RpcServer struct { + ln net.Listener + s *rpc.Server +} + +func NewRpcServer(addr string, receiver interface{}) (*RpcServer, error) { + ln, err := net.Listen("tcp", addr) + if err != nil { + return nil, fmt.Errorf("failed to listen on %v: %v", addr, err) + } + s := rpc.NewServer() + s.Register(receiver) + serv := &RpcServer{ + ln: ln, + s: s, + } + return serv, nil +} + +func (serv *RpcServer) Serve() { + for { + conn, err := serv.ln.Accept() + if err != nil { + Logf(0, "failed to accept an rpc connection: %v", err) + continue + } + conn.(*net.TCPConn).SetKeepAlive(true) + conn.(*net.TCPConn).SetKeepAlivePeriod(time.Minute) + go serv.s.ServeConn(conn) + } +} + +func (serv *RpcServer) Addr() net.Addr { + return serv.ln.Addr() +} + +type RpcClient struct { + conn net.Conn + c *rpc.Client +} + +func NewRpcClient(addr string) (*RpcClient, error) { + conn, err := net.DialTimeout("tcp", addr, 60*time.Second) + if err != nil { + return nil, err + } + conn.(*net.TCPConn).SetKeepAlive(true) + conn.(*net.TCPConn).SetKeepAlivePeriod(time.Minute) + cli := &RpcClient{ + conn: conn, + c: rpc.NewClient(conn), + } + return cli, nil +} + +func (cli *RpcClient) Call(method string, args, reply interface{}) error { + cli.conn.SetDeadline(time.Now().Add(5 * 60 * time.Second)) + err := cli.c.Call(method, args, reply) + cli.conn.SetDeadline(time.Time{}) + return err +} + +func (cli *RpcClient) Close() { + cli.c.Close() +} + +func RpcCall(addr, method string, args, reply interface{}) error { + c, err := NewRpcClient(addr) + if err != nil { + return err + } + defer c.Close() + return c.Call(method, args, reply) +} diff --git a/pkg/rpctype/rpctype.go b/pkg/rpctype/rpctype.go new file mode 100644 index 000000000..8b251b717 --- /dev/null +++ b/pkg/rpctype/rpctype.go @@ -0,0 +1,78 @@ +// Copyright 2015 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +// Package rpctype contains types of message passed via net/rpc connections +// between various parts of the system. +package rpctype + +type RpcInput struct { + Call string + Prog []byte + CallIndex int + Signal []uint32 + Cover []uint32 +} + +type RpcCandidate struct { + Prog []byte + Minimized bool +} + +type ConnectArgs struct { + Name string +} + +type ConnectRes struct { + Prios [][]float32 + Inputs []RpcInput + MaxSignal []uint32 + Candidates []RpcCandidate + EnabledCalls string + NeedCheck bool +} + +type CheckArgs struct { + Name string + Kcov bool + Leak bool + Fault bool + UserNamespaces bool + Calls []string +} + +type NewInputArgs struct { + Name string + RpcInput +} + +type PollArgs struct { + Name string + MaxSignal []uint32 + Stats map[string]uint64 +} + +type PollRes struct { + Candidates []RpcCandidate + NewInputs []RpcInput + MaxSignal []uint32 +} + +type HubConnectArgs struct { + Name string + Key string + Fresh bool + Calls []string + Corpus [][]byte +} + +type HubSyncArgs struct { + Name string + Key string + Add [][]byte + Del []string +} + +type HubSyncRes struct { + Inputs [][]byte + More int +} diff --git a/rpctype/rpc.go b/rpctype/rpc.go deleted file mode 100644 index 8400b0e95..000000000 --- a/rpctype/rpc.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2017 syzkaller project authors. All rights reserved. -// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. - -package rpctype - -import ( - "fmt" - "net" - "net/rpc" - "time" - - . "github.com/google/syzkaller/pkg/log" -) - -type RpcServer struct { - ln net.Listener - s *rpc.Server -} - -func NewRpcServer(addr string, receiver interface{}) (*RpcServer, error) { - ln, err := net.Listen("tcp", addr) - if err != nil { - return nil, fmt.Errorf("failed to listen on %v: %v", addr, err) - } - s := rpc.NewServer() - s.Register(receiver) - serv := &RpcServer{ - ln: ln, - s: s, - } - return serv, nil -} - -func (serv *RpcServer) Serve() { - for { - conn, err := serv.ln.Accept() - if err != nil { - Logf(0, "failed to accept an rpc connection: %v", err) - continue - } - conn.(*net.TCPConn).SetKeepAlive(true) - conn.(*net.TCPConn).SetKeepAlivePeriod(time.Minute) - go serv.s.ServeConn(conn) - } -} - -func (serv *RpcServer) Addr() net.Addr { - return serv.ln.Addr() -} - -type RpcClient struct { - conn net.Conn - c *rpc.Client -} - -func NewRpcClient(addr string) (*RpcClient, error) { - conn, err := net.DialTimeout("tcp", addr, 60*time.Second) - if err != nil { - return nil, err - } - conn.(*net.TCPConn).SetKeepAlive(true) - conn.(*net.TCPConn).SetKeepAlivePeriod(time.Minute) - cli := &RpcClient{ - conn: conn, - c: rpc.NewClient(conn), - } - return cli, nil -} - -func (cli *RpcClient) Call(method string, args, reply interface{}) error { - cli.conn.SetDeadline(time.Now().Add(5 * 60 * time.Second)) - err := cli.c.Call(method, args, reply) - cli.conn.SetDeadline(time.Time{}) - return err -} - -func (cli *RpcClient) Close() { - cli.c.Close() -} - -func RpcCall(addr, method string, args, reply interface{}) error { - c, err := NewRpcClient(addr) - if err != nil { - return err - } - defer c.Close() - return c.Call(method, args, reply) -} diff --git a/rpctype/rpctype.go b/rpctype/rpctype.go deleted file mode 100644 index 8b251b717..000000000 --- a/rpctype/rpctype.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 syzkaller project authors. All rights reserved. -// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. - -// Package rpctype contains types of message passed via net/rpc connections -// between various parts of the system. -package rpctype - -type RpcInput struct { - Call string - Prog []byte - CallIndex int - Signal []uint32 - Cover []uint32 -} - -type RpcCandidate struct { - Prog []byte - Minimized bool -} - -type ConnectArgs struct { - Name string -} - -type ConnectRes struct { - Prios [][]float32 - Inputs []RpcInput - MaxSignal []uint32 - Candidates []RpcCandidate - EnabledCalls string - NeedCheck bool -} - -type CheckArgs struct { - Name string - Kcov bool - Leak bool - Fault bool - UserNamespaces bool - Calls []string -} - -type NewInputArgs struct { - Name string - RpcInput -} - -type PollArgs struct { - Name string - MaxSignal []uint32 - Stats map[string]uint64 -} - -type PollRes struct { - Candidates []RpcCandidate - NewInputs []RpcInput - MaxSignal []uint32 -} - -type HubConnectArgs struct { - Name string - Key string - Fresh bool - Calls []string - Corpus [][]byte -} - -type HubSyncArgs struct { - Name string - Key string - Add [][]byte - Del []string -} - -type HubSyncRes struct { - Inputs [][]byte - More int -} diff --git a/syz-fuzzer/fuzzer.go b/syz-fuzzer/fuzzer.go index 09d3e5034..44c8d2b10 100644 --- a/syz-fuzzer/fuzzer.go +++ b/syz-fuzzer/fuzzer.go @@ -27,8 +27,8 @@ import ( "github.com/google/syzkaller/pkg/ipc" . "github.com/google/syzkaller/pkg/log" "github.com/google/syzkaller/pkg/osutil" + . "github.com/google/syzkaller/pkg/rpctype" "github.com/google/syzkaller/prog" - . "github.com/google/syzkaller/rpctype" "github.com/google/syzkaller/sys" ) diff --git a/syz-hub/hub.go b/syz-hub/hub.go index 1c237ddac..410660f9f 100644 --- a/syz-hub/hub.go +++ b/syz-hub/hub.go @@ -11,7 +11,7 @@ import ( "sync" . "github.com/google/syzkaller/pkg/log" - . "github.com/google/syzkaller/rpctype" + . "github.com/google/syzkaller/pkg/rpctype" "github.com/google/syzkaller/syz-hub/state" ) diff --git a/syz-manager/manager.go b/syz-manager/manager.go index 4d5fa8865..9ab0ce4f5 100644 --- a/syz-manager/manager.go +++ b/syz-manager/manager.go @@ -28,8 +28,8 @@ import ( "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" "github.com/google/syzkaller/pkg/repro" + . "github.com/google/syzkaller/pkg/rpctype" "github.com/google/syzkaller/prog" - . "github.com/google/syzkaller/rpctype" "github.com/google/syzkaller/syz-manager/mgrconfig" "github.com/google/syzkaller/vm" ) -- cgit mrf-deployment