From d1f40710383d178f84ded1370da3ddefd33410f5 Mon Sep 17 00:00:00 2001 From: Vaastav Anand Date: Thu, 31 May 2018 19:19:05 -0700 Subject: [PATCH 1/2] Move capture library from GoVector to Dinv repo --- capture/README.md | 54 ++++++ capture/capture.go | 281 ++++++++++++++++++++++++++++ capture/inst.go | 451 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 786 insertions(+) create mode 100644 capture/README.md create mode 100644 capture/capture.go create mode 100644 capture/inst.go diff --git a/capture/README.md b/capture/README.md new file mode 100644 index 0000000..7908a1c --- /dev/null +++ b/capture/README.md @@ -0,0 +1,54 @@ +#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](https://golang.org/pkg/net/). + +#Installing + +To install GoVector's capture tool run +``` +go install +``` +In GoVector's main directory + +#Dependencies + +GoVector depends on [Dinv](https://bitbucket.org/bestchai/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](https://golang.org/pkg/go/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](https://github.com/DistributedClocks/GoVector/blob/master/capture/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. + diff --git a/capture/capture.go b/capture/capture.go new file mode 100644 index 0000000..b1b05a7 --- /dev/null +++ b/capture/capture.go @@ -0,0 +1,281 @@ +package capture + +import ( + "bitbucket.org/bestchai/dinv/dinvRT" + "bufio" + + "encoding/gob" + "fmt" + "io" + "net" + "net/rpc" +) + +/* +Functions for appending vector clocks to the standard net package +*/ +func Read(read func([]byte) (int, error), b []byte) (int, error) { + buf := make([]byte, len(b)) + n, err := read(buf) + dinvRT.Unpack(buf, &b) + return n, err +} + +func ReadFrom(readFrom func([]byte) (int, net.Addr, error), b []byte) (int, net.Addr, error) { + buf := make([]byte, len(b)) + n, addr, err := readFrom(buf) + dinvRT.Unpack(buf, &b) + return n, addr, err +} + +func Write(write func(b []byte) (int, error), b []byte) (int, error) { + buf := dinvRT.Pack(b) + n, err := write(buf) + return n, err +} + +func WriteTo(writeTo func([]byte, net.Addr) (int, error), b []byte, addr net.Addr) (int, error) { + buf := dinvRT.Pack(b) + n, err := writeTo(buf, addr) + return n, err +} + +//Protocol specific funcions +func ReadFromIP(readfromip func([]byte) (int, *net.IPAddr, error), b []byte) (int, *net.IPAddr, error) { + buf := make([]byte, len(b)) + n, addr, err := readfromip(buf) + dinvRT.Unpack(buf, &b) + return n, addr, err +} + +func ReadMsgIP(readmsgip func([]byte, []byte) (int, int, int, *net.IPAddr, error), b, oob []byte) (int, int, int, *net.IPAddr, error) { + buf := make([]byte, len(b)) + n, oobn, flags, addr, err := readmsgip(buf, oob) + dinvRT.Unpack(buf, &b) + return n, oobn, flags, addr, err +} + +func WriteMsgIP(writemsgip func([]byte, []byte, *net.IPAddr) (int, int, error), b, oob []byte, addr *net.IPAddr) (int, int, error) { + buf := dinvRT.Pack(b) + n, oobn, err := writemsgip(buf, oob, addr) + return n, oobn, err +} + +func WriteToIP(writetoip func([]byte, *net.IPAddr) (int, error), b []byte, addr *net.IPAddr) (int, error) { + buf := dinvRT.Pack(b) + n, err := writetoip(buf, addr) + return n, err +} + +func ReadFromUDP(readfromudp func([]byte) (int, *net.UDPAddr, error), b []byte) (int, *net.UDPAddr, error) { + buf := make([]byte, len(b)) + n, addr, err := readfromudp(buf) + dinvRT.Unpack(buf, &b) + return n, addr, err +} + +func ReadMsgUDP(readmsgudp func([]byte, []byte) (int, int, int, *net.UDPAddr, error), b, oob []byte) (int, int, int, *net.UDPAddr, error) { + buf := make([]byte, len(b)) + n, oobn, flags, addr, err := readmsgudp(b, oob) + dinvRT.Unpack(buf, &b) + return n, oobn, flags, addr, err +} + +func WriteMsgUDP(writemsgudp func([]byte, []byte, *net.UDPAddr) (int, int, error), b, oob []byte, addr *net.UDPAddr) (int, int, error) { + buf := dinvRT.Pack(b) + n, oobn, err := writemsgudp(buf, oob, addr) + return n, oobn, err +} + +func WriteToUDP(writetoudp func([]byte, *net.UDPAddr) (int, error), b []byte, addr *net.UDPAddr) (int, error) { + buf := dinvRT.Pack(b) + n, err := writetoudp(buf, addr) + return n, err +} + +func ReadFromUnix(readfromunix func([]byte) (int, *net.UnixAddr, error), b []byte) (int, *net.UnixAddr, error) { + buf := make([]byte, len(b)) + n, addr, err := readfromunix(buf) + dinvRT.Unpack(buf, &b) + return n, addr, err +} + +func ReadMsgUnix(readmsgunix func([]byte, []byte) (int, int, int, *net.UnixAddr, error), b, oob []byte) (int, int, int, *net.UnixAddr, error) { + buf := make([]byte, len(b)) + n, oobn, flags, addr, err := readmsgunix(b, oob) + dinvRT.Unpack(buf, &b) + return n, oobn, flags, addr, err +} + +func WriteMsgUnix(writemsgunix func([]byte, []byte, *net.UnixAddr) (int, int, error), b, oob []byte, addr *net.UnixAddr) (int, int, error) { + buf := dinvRT.Pack(b) + n, oobn, err := writemsgunix(buf, oob, addr) + return n, oobn, err +} + +func WriteToUnix(writetounix func([]byte, *net.UnixAddr) (int, error), b []byte, addr *net.UnixAddr) (int, error) { + buf := dinvRT.Pack(b) + n, err := writetounix(buf, addr) + return n, err +} + +/* Functions to add Codecs to Client RPC calls */ +func Dial(dial func(string, string) (*rpc.Client, error), network, address string) (*rpc.Client, error) { + conn, err := net.Dial(network, address) + if err != nil { + return nil, err + } + return rpc.NewClientWithCodec(NewClientCodec(conn)), err +} + +//TODO +func DialHTTP(dialHttp func(string, string) (*rpc.Client, error), network, address string) (*rpc.Client, error) { + return nil, fmt.Errorf("Dinv has yet to implement an rpc.DialHTTP wrapper\n") +} + +//TODO +func DialHTTPPath(dialHttpPath func(string, string, string) (*rpc.Client, error), network, address, path string) (*rpc.Client, error) { + return nil, fmt.Errorf("Dinv has yet to implement an rpc.DialHTTP wrapper\n") +} + +func NewClient(newClient func(io.ReadWriteCloser) *rpc.Client, conn io.ReadWriteCloser) *rpc.Client { + return rpc.NewClientWithCodec(NewClientCodec(conn)) +} + +//TODO +func NewClientWithCodec(newClientWithCodec func(rpc.ClientCodec) *rpc.Client, codec rpc.ClientCodec) *rpc.Client { + return nil +} + +/* Functions for adding codecs to Server RPC */ + +//TODO +func ServeCodec(serveCodec func(rpc.ServerCodec), codec rpc.ServerCodec) { + return +} + +func ServeConn(serveConn func(io.ReadWriteCloser), conn io.ReadWriteCloser) { + rpc.DefaultServer.ServeCodec(NewServerCodec(conn)) +} + +//TODO +func ServeRequest(serveRequest func(rpc.ServerCodec) error, codec rpc.ServerCodec) error { + return fmt.Errorf("Dinv has yet to implement an rpc.ServeRequest wrapper\n") +} + +//TODO the interalfunction for the rpc.Server have yet to be +//implemented + +/* + Client Codec for instrumenting RPC calls with vector clocks +*/ + +type ClientClockCodec struct { + C io.Closer + Dec *gob.Decoder + Enc *gob.Encoder + EncBuf *bufio.Writer +} + +func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec { + encBuf := bufio.NewWriter(conn) + return &ClientClockCodec{conn, gob.NewDecoder(conn), gob.NewEncoder(encBuf), encBuf} +} + +func (c *ClientClockCodec) WriteRequest(req *rpc.Request, param interface{}) (err error) { + fmt.Println("WriteRequest") + if err = c.Enc.Encode(req); err != nil { + return + } + buf := dinvRT.Pack(param) + if err = c.Enc.Encode(buf); err != nil { + return + } + + return c.EncBuf.Flush() +} + +func (c *ClientClockCodec) ReadResponseHeader(resp *rpc.Response) error { + fmt.Println("ReadResponseHeader") + return c.Dec.Decode(resp) +} + +func (c *ClientClockCodec) ReadResponseBody(body interface{}) (err error) { + fmt.Println("ReadResponseBody") + var buf []byte + if err = c.Dec.Decode(&buf); err != nil { + return + } + dinvRT.Unpack(buf, body) + return nil +} + +func (c *ClientClockCodec) Close() error { + return c.C.Close() +} + +/* + Client Codec for instrumenting RPC calls with vector clocks +*/ + +type ServerClockCodec struct { + Rwc io.ReadWriteCloser + Dec *gob.Decoder + Enc *gob.Encoder + EncBuf *bufio.Writer + Closed bool +} + +func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec { + buf := bufio.NewWriter(conn) + srv := &ServerClockCodec{ + Rwc: conn, + Dec: gob.NewDecoder(conn), + Enc: gob.NewEncoder(buf), + EncBuf: buf, + } + return srv +} + +func (c *ServerClockCodec) ReadRequestHeader(r *rpc.Request) error { + fmt.Println("ReadRequestHeader") + return c.Dec.Decode(r) +} +func (c *ServerClockCodec) ReadRequestBody(body interface{}) (err error) { + fmt.Println("ReadResponseBody") + var buf []byte + if err = c.Dec.Decode(&buf); err != nil { + return + } + dinvRT.Unpack(buf, body) + return nil + +} +func (c *ServerClockCodec) WriteResponse(r *rpc.Response, body interface{}) (err error) { + if err = c.Enc.Encode(r); err != nil { + if c.EncBuf.Flush() == nil { + //Gob Encoding Error + fmt.Println("RPC Error encoding response:", err) + c.Close() + } + return + } + buf := dinvRT.Pack(body) + if err = c.Enc.Encode(buf); err != nil { + if c.EncBuf.Flush() == nil { + //Gob Encoding Error + fmt.Println("RPC Error encoding body (This is likely Dinv's fault):", err) + c.Close() + } + return + } + return c.EncBuf.Flush() +} + +func (c *ServerClockCodec) Close() error { + if c.Closed { + return nil + } + c.Closed = true + return c.Rwc.Close() +} diff --git a/capture/inst.go b/capture/inst.go new file mode 100644 index 0000000..53f3691 --- /dev/null +++ b/capture/inst.go @@ -0,0 +1,451 @@ +package capture + +import ( + "bitbucket.org/bestchai/dinv/programslicer" + "fmt" + "regexp" + "sort" + + "bytes" + "go/ast" + "go/importer" + "go/printer" + "go/token" + "go/types" + "golang.org/x/tools/go/ast/astutil" +) + +var ( + debug = false + Directory = "" + File = "" + Pipe = "" +) + +//types of communication calls +const ( + SENDING = iota + RECEIVING + BOTH + NOT +) + +func InsturmentComm(options map[string]string) map[string]string { + initalize(options) + p, err := getProgramWrapper() + if err != nil { + panic(err) + } + netConns := GetNetConns(p) + instrumentedOutput := make(map[string]string) + for pnum, pack := range p.Packages { + for snum, _ := range pack.Sources { + InstrumentCalls(p, pnum, snum, netConns) + buf := new(bytes.Buffer) + printer.Fprint(buf, p.Fset, p.Packages[pnum].Sources[snum].Comments) + p.Packages[pnum].Sources[snum].Text = buf.String() + instrumentedOutput[p.Packages[pnum].Sources[snum].Filename] = buf.String() + } + } + return instrumentedOutput +} + +func initalize(options map[string]string) { + for setting := range options { + switch setting { + case "debug": + debug = true + case "directory": + Directory = options[setting] + case "file": + File = options[setting] + case "pipe": + Pipe = options[setting] + default: + continue + } + } +} + +func getProgramWrapper() (*programslicer.ProgramWrapper, error) { + var ( + program *programslicer.ProgramWrapper + err error + ) + if Directory != "" { + program, err = programslicer.GetProgramWrapperDirectory(Directory) + if err != nil { + return program, err + } + } else if File != "" { + program, err = programslicer.GetProgramWrapperFile(File) + if err != nil { + return program, err + } + } else if Pipe != "" { + program, err = programslicer.GetWrapperFromString(Pipe) + if err != nil { + return program, err + } + } + return program, nil +} + +func GetCommNodes(p *programslicer.ProgramWrapper) (sending, receiving, both []*ast.Node) { + netConns := GetNetConns(p) + for _, pack := range p.Packages { + for _, src := range pack.Sources { + ast.Inspect(src.Source, func(n ast.Node) bool { + status := NOT // the type of call that was made + switch z := n.(type) { + case *ast.ExprStmt: + switch c := z.X.(type) { + case *ast.CallExpr: + status = checkCall(p, c, netConns) + } + case *ast.AssignStmt: + switch c := z.Rhs[0].(type) { + case *ast.CallExpr: + status = checkCall(p, c, netConns) + } + } + switch status { + case SENDING: + sending = append(sending, &n) + break + case RECEIVING: + receiving = append(receiving, &n) + break + case BOTH: + both = append(both, &n) + break + default: + break + } + return true + }) + } + } + fmt.Printf("sending %d receiving %d both %d", len(sending), len(receiving), len(both)) + return +} + +//check call takes program wrapper, call expersion and set of +//POPULATED net connections as an arguments. The call expression is +//checked againts the set of known net connections for type. If the +//an enum denoting the type of connection is returned +func checkCall(p *programslicer.ProgramWrapper, c *ast.CallExpr, netConns map[types.Object]*NetConn) int { + switch f := c.Fun.(type) { + case *ast.SelectorExpr: + switch i := f.X.(type) { + case *ast.Ident: + for obj, conn := range netConns { + if i.Obj != nil { + //fmt.Printf("obj-Id: %s\t obj-Pkg: %s\tsearch-Obj.Name: %s\t searchObjPos:%d\t obj-Pos%d\n",obj.Id(),obj.Pkg().Name(),i.Name,i.Obj.Pos(),obj.Pos()) + } + if (i.Obj != nil && obj.Pos() == i.Obj.Pos()) || (obj.Pkg().Name() == i.Name) { + fmt.Println("MATCH") + if check(f.Sel.Name, conn.ReceivingFunctions, c, p) { + return RECEIVING + } else if check(f.Sel.Name, conn.SenderFunctions, c, p) { + return SENDING + } else if check(f.Sel.Name, conn.ConnectionFunctions, c, p) { + return BOTH + } else { + return NOT + } + } + } + } + } + return NOT +} + +//check compaires a variable name with the nown set of +//networking functions. If a match is made, true is returned. +func check(varName string, netfuncs []*NetFunc, call *ast.CallExpr, p *programslicer.ProgramWrapper) bool { + for _, netFunc := range netfuncs { + fmt.Printf("varName = %s, netFunc.Name = %s\n", varName, netFunc.Name) + if varName == netFunc.Name { + return true + } + } + return false +} + +func InstrumentCalls(p *programslicer.ProgramWrapper, pnum, snum int, netConns map[types.Object]*NetConn) { + injected := false + ast.Inspect(p.Packages[pnum].Sources[snum].Comments, func(n ast.Node) bool { + switch c := n.(type) { + case *ast.CallExpr: + switch f := c.Fun.(type) { + case *ast.SelectorExpr: + switch i := f.X.(type) { + case *ast.Ident: + for obj, conn := range netConns { + if i.Obj != nil { + //fmt.Printf("nc-obj-Pkg: %s\t nc-obj-Id: %s\t\t found-obj-name: %s\t\t searchObjPos:%d\t\t obj-Pos:%d\n",obj.Pkg().Name(),obj.Id(), i.Name,i.Obj.Pos(),obj.Pos()) + } + if (i.Obj != nil && obj.Pos() == i.Obj.Pos()) || (obj.Pkg().Name() == i.Name) { + //fmt.Println("MATCH") + injected = checkAndInstrument(f.Sel.Name, conn.ReceivingFunctions, c, p) || injected + injected = checkAndInstrument(f.Sel.Name, conn.SenderFunctions, c, p) || injected + injected = checkAndInstrument(f.Sel.Name, conn.ConnectionFunctions, c, p) || injected + } + } + } + } + } + return true + }) + //if code was added, add the apropriate import + if injected { + astutil.AddImport(p.Fset, p.Packages[pnum].Sources[snum].Comments, "github.com/DistributedClocks/GoVector/capture") + } + +} + +//checkAndInstrument compaires a variable name with the nown set of +//networking functions. If the variable is found to be a networking +//function, it is captured. +//If the variable is insturmented the function returns true. +func checkAndInstrument(varName string, netfuncs []*NetFunc, call *ast.CallExpr, p *programslicer.ProgramWrapper) bool { + for _, netFunc := range netfuncs { + //fmt.Printf("varName = %s, netFunc.Name = %s\n",varName,netFunc.Name) + if varName == netFunc.Name { + instrumentCall(call, netFunc) + return true + } + } + return false +} + +func instrumentCall(call *ast.CallExpr, function *NetFunc) { + funString := getFunctionString(call) + args := getArgsString(call.Args) + call.Fun = ast.NewIdent(fmt.Sprintf("capture.%s", function.Name)) + call.Args = make([]ast.Expr, 1) + call.Args[0] = ast.NewIdent(fmt.Sprintf("%s,%s", funString, args)) +} + +func getFunctionString(call *ast.CallExpr) string { + fset := token.NewFileSet() + var buf bytes.Buffer + printer.Fprint(&buf, fset, call.Fun) + return buf.String() +} + +func getArgsString(args []ast.Expr) string { + fset := token.NewFileSet() + var buf bytes.Buffer + argsString := make([]string, 0) + for i := range args { + buf.Reset() + printer.Fprint(&buf, fset, args[i]) + argsString = append(argsString, buf.String()) + } + + var output string + for i := 0; i < len(argsString)-1; i++ { + output += argsString[i] + "," + } + output += argsString[len(argsString)-1] + return output +} + +//TODO merge with Get SendReceiveNodes +//GetNetConns searches through a program for net connections, and +//adds their object reference to a known database +func GetNetConns(program *programslicer.ProgramWrapper) map[types.Object]*NetConn { + // Type-check the package. + // We create an empty map for each kind of input + // we're interested in, and Check populates them. + info := types.Info{ + Types: make(map[ast.Expr]types.TypeAndValue), + Defs: make(map[*ast.Ident]types.Object), + Uses: make(map[*ast.Ident]types.Object), + } + //var conf types.Config + conf := types.Config{Importer: importer.Default()} + + sources := make([]*ast.File, 0) + for _, source := range program.Packages[0].Sources { //TODO extend to interpackage + sources = append(sources, source.Comments) //NOTE CHANGED FROM SOURCES (SHOULD BE SOURCES) /Trying to figure out why obj-pos() not working for the checking function + } + pkg, err := conf.Check(program.Packages[0].PackageName, program.Fset, sources, &info) //TODO extend to interpackage + if err != nil { + fmt.Println(err) + } + + usesByObj := make(map[types.Object][]string) + for id, obj := range info.Uses { + posn := program.Fset.Position(id.Pos()) + lineCol := fmt.Sprintf("%d:%d", posn.Line, posn.Column) + usesByObj[obj] = append(usesByObj[obj], lineCol) + } + //capture variables name type + revar := regexp.MustCompile(`var ([A-Za-z0-9_]+) \**([*.A-Za-z0-9_]+)`) + refunc := regexp.MustCompile(`func ([A-Za-z0-9_/]+).([A-Za-z0-9_]+)\(`) + var netConns map[types.Object]*NetConn = make(map[types.Object]*NetConn, 0) + + for obj, uses := range usesByObj { + sort.Strings(uses) + ObjectDef := types.ObjectString(obj, types.RelativeTo(pkg)) + + //fmt.Println(ObjectDef) + //variables + match := revar.FindStringSubmatch(ObjectDef) + //fmt.Println(match) + if len(match) == 3 { + //type is in netvars + _, ok := NetDB[match[2]] //match[2] contians the type of the object + if ok { + netConns[obj] = NetDB[match[2]] + } + } + //variables + match = refunc.FindStringSubmatch(ObjectDef) + //fmt.Println(match) + if len(match) == 3 { + //type is in netvars + _, ok := NetDB[match[1]] //match[2] contians the type of the object + if ok { + netConns[obj] = NetDB[match[1]] + //fmt.Printf("Added Obj: %s to the DB\n",obj.String()) + } + } + } + for conn := range netConns { + fmt.Println(conn.String()) + } + + return netConns + //NOTE This is where the differences between detects + //GetSendReceiveNodes differes +} + +type NetConn struct { + NetType string + SenderFunctions []*NetFunc + ReceivingFunctions []*NetFunc + ConnectionFunctions []*NetFunc +} + +type NetFunc struct { + Name string + Args int + Returns int + PrimaryArgLoc int + ReturnSizeLoc int +} + +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{"ReadFrom",1,3,0,0}, //This + //weird method takes an io.Reader as an + //argument rather that a buffer + }, + []*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.Server" : &NetConn{ + "rpc.Server", + []*NetFunc{}, + []*NetFunc{}, + []*NetFunc{ + &NetFunc{"ServerCodec",1,0,0,0}, + &NetFunc{"ServerConn",1,0,0,0}, + &NetFunc{"ServeHTTP",2,0,?,0}, + &NetFunc{"ServeRequest",1,0,0,0}, + }, + },*/ + "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}, + }, + }, +} From a2f2f3a0ff10ec157af620d3cefceea8fe738198 Mon Sep 17 00:00:00 2001 From: Vaastav Anand Date: Thu, 31 May 2018 19:34:34 -0700 Subject: [PATCH 2/2] CHange files to use capture library located in dinv instead of the ones in GoVector --- capture/inst.go | 2 +- dinvRT/test-asserts/diningPhilosophers/diningphilosopher.go | 2 +- dinvRT/test-asserts/microbenchmark_tests/node.go | 2 +- dinvRT/test-asserts/ricartagrawala/ricartagrawala.go | 2 +- dinvRT/test-asserts/sum/client/client.go | 2 +- dinvRT/test-asserts/sum/server/server.go | 2 +- examples/diningPhil/diningphilosopher.go | 2 +- examples/linear/coeff/coeff.go | 2 +- examples/linear/linn/linn.go | 2 +- examples/ricartagrawala/ricartagrawala.go | 2 +- examples/ring/node.go | 2 +- examples/sum/client/client.go | 2 +- examples/sum/server/server.go | 2 +- instrumenter/instrumenter.go | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/capture/inst.go b/capture/inst.go index 53f3691..bb1a757 100644 --- a/capture/inst.go +++ b/capture/inst.go @@ -200,7 +200,7 @@ func InstrumentCalls(p *programslicer.ProgramWrapper, pnum, snum int, netConns m }) //if code was added, add the apropriate import if injected { - astutil.AddImport(p.Fset, p.Packages[pnum].Sources[snum].Comments, "github.com/DistributedClocks/GoVector/capture") + astutil.AddImport(p.Fset, p.Packages[pnum].Sources[snum].Comments, "bitbucket.org/bestchai/dinv/capture") } } diff --git a/dinvRT/test-asserts/diningPhilosophers/diningphilosopher.go b/dinvRT/test-asserts/diningPhilosophers/diningphilosopher.go index 042a507..6d0ab45 100644 --- a/dinvRT/test-asserts/diningPhilosophers/diningphilosopher.go +++ b/dinvRT/test-asserts/diningPhilosophers/diningphilosopher.go @@ -4,7 +4,7 @@ import ( "bitbucket.org/bestchai/dinv/dinvRT" "flag" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "math/rand" "net" "os" diff --git a/dinvRT/test-asserts/microbenchmark_tests/node.go b/dinvRT/test-asserts/microbenchmark_tests/node.go index 7b4e952..d0e42d5 100644 --- a/dinvRT/test-asserts/microbenchmark_tests/node.go +++ b/dinvRT/test-asserts/microbenchmark_tests/node.go @@ -6,7 +6,7 @@ import ( "encoding/gob" "flag" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "io" "log" "math/rand" diff --git a/dinvRT/test-asserts/ricartagrawala/ricartagrawala.go b/dinvRT/test-asserts/ricartagrawala/ricartagrawala.go index 71de7b9..88cc774 100644 --- a/dinvRT/test-asserts/ricartagrawala/ricartagrawala.go +++ b/dinvRT/test-asserts/ricartagrawala/ricartagrawala.go @@ -6,7 +6,7 @@ import ( "encoding/gob" "flag" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "io" "log" "math/rand" diff --git a/dinvRT/test-asserts/sum/client/client.go b/dinvRT/test-asserts/sum/client/client.go index 33c7995..89b8b8a 100755 --- a/dinvRT/test-asserts/sum/client/client.go +++ b/dinvRT/test-asserts/sum/client/client.go @@ -4,7 +4,7 @@ import ( "bitbucket.org/bestchai/dinv/dinvRT" "encoding/binary" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "math/rand" "net" "os" diff --git a/dinvRT/test-asserts/sum/server/server.go b/dinvRT/test-asserts/sum/server/server.go index 93ddf0e..40ec34e 100755 --- a/dinvRT/test-asserts/sum/server/server.go +++ b/dinvRT/test-asserts/sum/server/server.go @@ -4,7 +4,7 @@ import ( "bitbucket.org/bestchai/dinv/dinvRT" "encoding/binary" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "net" "os" "time" diff --git a/examples/diningPhil/diningphilosopher.go b/examples/diningPhil/diningphilosopher.go index e16a3c2..3164314 100644 --- a/examples/diningPhil/diningphilosopher.go +++ b/examples/diningPhil/diningphilosopher.go @@ -4,7 +4,7 @@ import ( "bitbucket.org/bestchai/dinv/dinvRT" "flag" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "math/rand" "net" "os" diff --git a/examples/linear/coeff/coeff.go b/examples/linear/coeff/coeff.go index b535308..b912c7b 100755 --- a/examples/linear/coeff/coeff.go +++ b/examples/linear/coeff/coeff.go @@ -7,7 +7,7 @@ import ( "os" "bitbucket.org/bestchai/dinv/dinvRT" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" ) const ( diff --git a/examples/linear/linn/linn.go b/examples/linear/linn/linn.go index 0f0f1f2..2796b7e 100755 --- a/examples/linear/linn/linn.go +++ b/examples/linear/linn/linn.go @@ -6,7 +6,7 @@ import ( "os" "bitbucket.org/bestchai/dinv/dinvRT" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" ) //var debug = false diff --git a/examples/ricartagrawala/ricartagrawala.go b/examples/ricartagrawala/ricartagrawala.go index cc97dcd..6260785 100644 --- a/examples/ricartagrawala/ricartagrawala.go +++ b/examples/ricartagrawala/ricartagrawala.go @@ -6,7 +6,7 @@ import ( "encoding/gob" "flag" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "io" "log" "math/rand" diff --git a/examples/ring/node.go b/examples/ring/node.go index bdc0548..f3f84a0 100644 --- a/examples/ring/node.go +++ b/examples/ring/node.go @@ -5,7 +5,7 @@ import ( "encoding/binary" "flag" "fmt" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "log" "net" "os" diff --git a/examples/sum/client/client.go b/examples/sum/client/client.go index d374d3b..ffd0fce 100755 --- a/examples/sum/client/client.go +++ b/examples/sum/client/client.go @@ -8,7 +8,7 @@ import ( "os" "bitbucket.org/bestchai/dinv/dinvRT" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" ) const ( diff --git a/examples/sum/server/server.go b/examples/sum/server/server.go index b2f6790..6947917 100755 --- a/examples/sum/server/server.go +++ b/examples/sum/server/server.go @@ -8,7 +8,7 @@ import ( "bitbucket.org/bestchai/dinv/dinvRT" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" ) const addr = ":9090" diff --git a/instrumenter/instrumenter.go b/instrumenter/instrumenter.go index c802d7e..bfa4d19 100755 --- a/instrumenter/instrumenter.go +++ b/instrumenter/instrumenter.go @@ -23,7 +23,7 @@ import ( "strings" "bitbucket.org/bestchai/dinv/programslicer" - "github.com/arcaneiceman/GoVector/capture" + "bitbucket.org/bestchai/dinv/capture" "golang.org/x/tools/go/ast/astutil" )