capture

package
v0.0.0-...-9ee40ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2018 License: MIT Imports: 17 Imported by: 0

README

#Capture networking calls for automatic instrumentation!

GoVector's capture library automatically injects vector clocks onto network reads and writes. The capture functionality works on the standard go net libary.

#Installing

To install GoVector's capture tool run

go install

In GoVector's main directory

#Dependencies

GoVector depends on Dinv for static analysis.

#How it works

GoVector capture takes either a go file or directory containing a go package as a command line argument. The package or file is then translated into its AST representation. GoVector traverses the AST searching for read and write calls to go's networking library. When matching calls are identified Capture performs an AST rotation and injects wrapper code for the networking call. The wrapper code appends and truncates vector clocks from network payloads. The set of library wrapping function are in capture.go The result of running Capture is an augmented file, or directory. Case specific auto instrumentation's of both Go's RPC, and HTTP are also implemented by Capture. Below is an example of a captured write.

###Before ```n, err := conn.Write(buf)``

###After ```n, err := capture.Write(conn.Write,buf)``

#Running

To run Capture on a single file run GoVector -f=filename.go

To run Capture on a directory containing a single package run GoVector -dir=directory

#Limitations

##Scale Building an AST in go requires that all referenced files are read in while building the AST. Capture will fail if a single go file with references to another local file is passed in. In this case the -dir option is suggests. The AST loading library only works on a single package at a time. Therefore Capture cannot instrument more than one package at a time.

##Aliasing Only calls to Go's standard networking library are completely supported. The net.Conn type implements io.ReadWriter, therefore it can be passed to an encoder or decoder directly. Capture makes no attempt to reason about which encoders or decoders could be attached to network connections. Encoder wrapped connections will not be instrumented.

Documentation

Index

Constants

View Source
const (
	SENDING = iota
	RECEIVING
	BOTH
	NOT
)

types of communication calls

Variables

View Source
var (
	Directory = ""
	File      = ""
	Pipe      = ""
)
View Source
var NetDB map[string]*NetConn = map[string]*NetConn{
	"net.UDPConn": &NetConn{
		"net.UDPConn",
		[]*NetFunc{
			&NetFunc{"Write", 1, 2, 0, 0},
			&NetFunc{"WriteMsgUDP", 2, 2, 0, 0},
			&NetFunc{"WriteTo", 2, 2, 0, 0},
			&NetFunc{"WriteToUDP", 2, 2, 0, 0},
		},
		[]*NetFunc{
			&NetFunc{"Read", 1, 2, 0, 0},
			&NetFunc{"ReadFrom", 1, 3, 0, 0},
			&NetFunc{"ReadFromUDP", 1, 3, 0, 0},
			&NetFunc{"ReadMsgUDP", 2, 5, 0, 0},
		},
		[]*NetFunc{},
	},
	"net.UnixConn": &NetConn{
		"net.UnixConn",
		[]*NetFunc{
			&NetFunc{"Write", 1, 2, 0, 0},
			&NetFunc{"WriteMsgUnix", 3, 3, 0, 0},
			&NetFunc{"WriteTo", 2, 2, 0, 0},
			&NetFunc{"WriteToUnix", 2, 2, 0, 0},
		},
		[]*NetFunc{
			&NetFunc{"Read", 1, 2, 0, 0},
			&NetFunc{"ReadFrom", 1, 3, 0, 0},
			&NetFunc{"ReadFromUDP", 1, 3, 0, 0},
			&NetFunc{"ReadMsgUDP", 2, 5, 0, 0},
		},
		[]*NetFunc{},
	},
	"net.IPConn": &NetConn{
		"net.IPConn",
		[]*NetFunc{
			&NetFunc{"Write", 1, 2, 0, 0},
			&NetFunc{"WriteMsgIP", 2, 2, 0, 0},
			&NetFunc{"WriteTo", 2, 2, 0, 0},
			&NetFunc{"WriteToIP", 2, 2, 0, 0},
		},
		[]*NetFunc{
			&NetFunc{"Read", 1, 2, 0, 0},
			&NetFunc{"ReadFrom", 1, 3, 0, 0},
			&NetFunc{"ReadFromIP", 1, 3, 0, 0},
			&NetFunc{"ReadMsgIP", 2, 5, 0, 0},
		},
		[]*NetFunc{},
	},
	"net.TCPConn": &NetConn{
		"net.TCPConn",
		[]*NetFunc{
			&NetFunc{"Write", 1, 2, 0, 0},
		},
		[]*NetFunc{
			&NetFunc{"Read", 1, 2, 0, 0},
		},
		[]*NetFunc{},
	},
	"net.PacketConn": &NetConn{
		"net.PacketConn",
		[]*NetFunc{
			&NetFunc{"WriteTo", 2, 2, 0, 0},
		},
		[]*NetFunc{
			&NetFunc{"ReadFrom", 1, 3, 0, 0},
		},
		[]*NetFunc{},
	},
	"net.Conn": &NetConn{
		"net.Conn",
		[]*NetFunc{
			&NetFunc{"Write", 2, 2, 0, 0},
		},
		[]*NetFunc{
			&NetFunc{"Read", 1, 3, 0, 0},
		},
		[]*NetFunc{},
	},

	"net/rpc": &NetConn{
		"rpc",
		[]*NetFunc{},
		[]*NetFunc{},
		[]*NetFunc{
			&NetFunc{"Dial", 2, 2, 0, 0},
			&NetFunc{"DialHTTP", 3, 2, 0, 0},
			&NetFunc{"DialHTTPPath", 3, 2, 0, 0},
			&NetFunc{"NewClient", 1, 0, 0, 0},
			&NetFunc{"NewClientWithCodec", 1, 0, 0, 0},
			&NetFunc{"ServeCodec", 1, 0, 0, 0},
			&NetFunc{"ServeConn", 1, 0, 0, 0},
			&NetFunc{"ServeRequest", 1, 0, 0, 0},
		},
	},
}

Functions

func Dial

func Dial(dial func(string, string) (*rpc.Client, error), network, address string) (*rpc.Client, error)

Functions to add Codecs to Client RPC calls

func DialHTTP

func DialHTTP(dialHttp func(string, string) (*rpc.Client, error), network, address string) (*rpc.Client, error)

TODO

func DialHTTPPath

func DialHTTPPath(dialHttpPath func(string, string, string) (*rpc.Client, error), network, address, path string) (*rpc.Client, error)

TODO

func GetCommNodes

func GetCommNodes(p *programslicer.ProgramWrapper) (sending, receiving, both []*ast.Node)

func GetNetConns

func GetNetConns(program *programslicer.ProgramWrapper) map[types.Object]*NetConn

TODO merge with Get SendReceiveNodes GetNetConns searches through a program for net connections, and adds their object reference to a known database

func InstrumentCalls

func InstrumentCalls(p *programslicer.ProgramWrapper, pnum, snum int, netConns map[types.Object]*NetConn)

func InsturmentComm

func InsturmentComm(options map[string]string) map[string]string

func NewClient

func NewClient(newClient func(io.ReadWriteCloser) *rpc.Client, conn io.ReadWriteCloser) *rpc.Client

func NewClientCodec

func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec

func NewClientWithCodec

func NewClientWithCodec(newClientWithCodec func(rpc.ClientCodec) *rpc.Client, codec rpc.ClientCodec) *rpc.Client

TODO

func NewServerCodec

func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec

func Read

func Read(read func([]byte) (int, error), b []byte) (int, error)

Functions for appending vector clocks to the standard net package

func ReadFrom

func ReadFrom(readFrom func([]byte) (int, net.Addr, error), b []byte) (int, net.Addr, error)

func ReadFromIP

func ReadFromIP(readfromip func([]byte) (int, *net.IPAddr, error), b []byte) (int, *net.IPAddr, error)

Protocol specific funcions

func ReadFromUDP

func ReadFromUDP(readfromudp func([]byte) (int, *net.UDPAddr, error), b []byte) (int, *net.UDPAddr, error)

func ReadFromUnix

func ReadFromUnix(readfromunix func([]byte) (int, *net.UnixAddr, error), b []byte) (int, *net.UnixAddr, error)

func ReadMsgIP

func ReadMsgIP(readmsgip func([]byte, []byte) (int, int, int, *net.IPAddr, error), b, oob []byte) (int, int, int, *net.IPAddr, error)

func ReadMsgUDP

func ReadMsgUDP(readmsgudp func([]byte, []byte) (int, int, int, *net.UDPAddr, error), b, oob []byte) (int, int, int, *net.UDPAddr, error)

func ReadMsgUnix

func ReadMsgUnix(readmsgunix func([]byte, []byte) (int, int, int, *net.UnixAddr, error), b, oob []byte) (int, int, int, *net.UnixAddr, error)

func ServeCodec

func ServeCodec(serveCodec func(rpc.ServerCodec), codec rpc.ServerCodec)

TODO

func ServeConn

func ServeConn(serveConn func(io.ReadWriteCloser), conn io.ReadWriteCloser)

func ServeRequest

func ServeRequest(serveRequest func(rpc.ServerCodec) error, codec rpc.ServerCodec) error

TODO

func Write

func Write(write func(b []byte) (int, error), b []byte) (int, error)

func WriteMsgIP

func WriteMsgIP(writemsgip func([]byte, []byte, *net.IPAddr) (int, int, error), b, oob []byte, addr *net.IPAddr) (int, int, error)

func WriteMsgUDP

func WriteMsgUDP(writemsgudp func([]byte, []byte, *net.UDPAddr) (int, int, error), b, oob []byte, addr *net.UDPAddr) (int, int, error)

func WriteMsgUnix

func WriteMsgUnix(writemsgunix func([]byte, []byte, *net.UnixAddr) (int, int, error), b, oob []byte, addr *net.UnixAddr) (int, int, error)

func WriteTo

func WriteTo(writeTo func([]byte, net.Addr) (int, error), b []byte, addr net.Addr) (int, error)

func WriteToIP

func WriteToIP(writetoip func([]byte, *net.IPAddr) (int, error), b []byte, addr *net.IPAddr) (int, error)

func WriteToUDP

func WriteToUDP(writetoudp func([]byte, *net.UDPAddr) (int, error), b []byte, addr *net.UDPAddr) (int, error)

func WriteToUnix

func WriteToUnix(writetounix func([]byte, *net.UnixAddr) (int, error), b []byte, addr *net.UnixAddr) (int, error)

Types

type ClientClockCodec

type ClientClockCodec struct {
	C      io.Closer
	Dec    *gob.Decoder
	Enc    *gob.Encoder
	EncBuf *bufio.Writer
}

func (*ClientClockCodec) Close

func (c *ClientClockCodec) Close() error

func (*ClientClockCodec) ReadResponseBody

func (c *ClientClockCodec) ReadResponseBody(body interface{}) (err error)

func (*ClientClockCodec) ReadResponseHeader

func (c *ClientClockCodec) ReadResponseHeader(resp *rpc.Response) error

func (*ClientClockCodec) WriteRequest

func (c *ClientClockCodec) WriteRequest(req *rpc.Request, param interface{}) (err error)

type NetConn

type NetConn struct {
	NetType             string
	SenderFunctions     []*NetFunc
	ReceivingFunctions  []*NetFunc
	ConnectionFunctions []*NetFunc
}

type NetFunc

type NetFunc struct {
	Name          string
	Args          int
	Returns       int
	PrimaryArgLoc int
	ReturnSizeLoc int
}

type ServerClockCodec

type ServerClockCodec struct {
	Rwc    io.ReadWriteCloser
	Dec    *gob.Decoder
	Enc    *gob.Encoder
	EncBuf *bufio.Writer
	Closed bool
}

func (*ServerClockCodec) Close

func (c *ServerClockCodec) Close() error

func (*ServerClockCodec) ReadRequestBody

func (c *ServerClockCodec) ReadRequestBody(body interface{}) (err error)

func (*ServerClockCodec) ReadRequestHeader

func (c *ServerClockCodec) ReadRequestHeader(r *rpc.Request) error

func (*ServerClockCodec) WriteResponse

func (c *ServerClockCodec) WriteResponse(r *rpc.Response, body interface{}) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL