Skip to content

Commit 45276ce

Browse files
linted vrpc
1 parent 945be60 commit 45276ce

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

govec/vrpc/vrpc.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//GoVector provides support for automatically logging RPC Calls from a
2-
//RPC Client to a RPC Server
1+
//Package vrpc provides support for automatically logging RPC Calls
2+
//from a RPC Client to a RPC Server
33
package vrpc
44

55
import (
@@ -24,10 +24,10 @@ func RPCDial(network, address string, logger *govec.GoLog) (*rpc.Client, error)
2424
return rpc.NewClientWithCodec(newClientCodec(conn, logger)), err
2525
}
2626

27-
//Convenience function that accepts connections for a given listener and
28-
//starts a new goroutine for the server to serve a new connection. The
29-
//logger is provided to be used by the RPCServerCodec for message
30-
//capture.
27+
//ServeRPCCon is a convenience function that accepts connections for a
28+
//given listener and starts a new goroutine for the server to serve a
29+
//new connection. The logger is provided to be used by the
30+
//RPCServerCodec for message capture.
3131
func ServeRPCConn(server *rpc.Server, l net.Listener, logger *govec.GoLog) {
3232
for {
3333
conn, err := l.Accept()
@@ -39,9 +39,9 @@ func ServeRPCConn(server *rpc.Server, l net.Listener, logger *govec.GoLog) {
3939
}
4040
}
4141

42-
//An extension of the default rpc codec which uses a logger of type
43-
//GoLog to capture all the calls to a RPC Server as well as responses
44-
//from a RPC server.
42+
//RPCClientCodec is an extension of the default rpc codec which uses a
43+
//logger of type GoLog to capture all the calls to a RPC Server as
44+
//well as responses from a RPC server.
4545
type RPCClientCodec struct {
4646
C io.Closer
4747
Dec *gob.Decoder
@@ -50,9 +50,9 @@ type RPCClientCodec struct {
5050
Logger *govec.GoLog
5151
}
5252

53-
//An extension of the default rpc codec which uses a logger of type of
54-
//GoLog to capture all the requests made from the client to a RPC server
55-
//as well as the server's to the clients.
53+
//RPCServerCodec is an extension of the default rpc codec which uses a
54+
//logger of type of GoLog to capture all the requests made from the
55+
//client to a RPC server as well as the server's to the clients.
5656
type RPCServerCodec struct {
5757
Rwc io.ReadWriteCloser
5858
Dec *gob.Decoder
@@ -62,6 +62,7 @@ type RPCServerCodec struct {
6262
Closed bool
6363
}
6464

65+
//NewClient returs an rpc.Client insturmented with vector clocks.
6566
func NewClient(conn io.ReadWriteCloser, logger *govec.GoLog) *rpc.Client {
6667
return rpc.NewClientWithCodec(newClientCodec(conn, logger))
6768
}
@@ -71,6 +72,8 @@ func newClientCodec(conn io.ReadWriteCloser, logger *govec.GoLog) rpc.ClientCode
7172
return &RPCClientCodec{conn, gob.NewDecoder(conn), gob.NewEncoder(encBuf), encBuf, logger}
7273
}
7374

75+
//WriteRequest marshalls and sends an rpc request, and it's associated
76+
//parameters to an RPC server
7477
func (c *RPCClientCodec) WriteRequest(req *rpc.Request, param interface{}) (err error) {
7578
if err = c.Enc.Encode(req); err != nil {
7679
return
@@ -83,10 +86,13 @@ func (c *RPCClientCodec) WriteRequest(req *rpc.Request, param interface{}) (err
8386
return c.EncBuf.Flush()
8487
}
8588

89+
//ReadResponseHeader deacodes an RPC response header on the client
8690
func (c *RPCClientCodec) ReadResponseHeader(resp *rpc.Response) error {
8791
return c.Dec.Decode(resp)
8892
}
8993

94+
//ReadResponseBody decodes a response body and updates it's local
95+
//vector clock with that of the server.
9096
func (c *RPCClientCodec) ReadResponseBody(body interface{}) (err error) {
9197
var buf []byte
9298
if err = c.Dec.Decode(&buf); err != nil {
@@ -96,6 +102,7 @@ func (c *RPCClientCodec) ReadResponseBody(body interface{}) (err error) {
96102
return nil
97103
}
98104

105+
//Close closes an RPCClientCodecs internal TCP connection
99106
func (c *RPCClientCodec) Close() error {
100107
return c.C.Close()
101108
}
@@ -112,10 +119,13 @@ func newServerCodec(conn io.ReadWriteCloser, logger *govec.GoLog) rpc.ServerCode
112119
return srv
113120
}
114121

122+
//ReadRequestHeader decodes a server rpc request header
115123
func (c *RPCServerCodec) ReadRequestHeader(r *rpc.Request) error {
116124
return c.Dec.Decode(r)
117125
}
118126

127+
//ReadRequestBody decodes a clinet request and updates the servers
128+
//local vector clock with the clients values
119129
func (c *RPCServerCodec) ReadRequestBody(body interface{}) (err error) {
120130
var buf []byte
121131
if err = c.Dec.Decode(&buf); err != nil {
@@ -125,13 +135,17 @@ func (c *RPCServerCodec) ReadRequestBody(body interface{}) (err error) {
125135
return nil
126136
}
127137

138+
//WriteResponse sends an rpc response, and it's associated result back
139+
//to the client
128140
func (c *RPCServerCodec) WriteResponse(r *rpc.Response, body interface{}) (err error) {
129141
Encode(c, r)
130142
buf := c.Logger.PrepareSend("Sending response to RPC request", body)
131143
Encode(c, buf)
132144
return c.EncBuf.Flush()
133145
}
134146

147+
//Encode is a convience function which writes to the wire and handels
148+
//RPC errors
135149
func Encode(c *RPCServerCodec, payload interface{}) {
136150
if err := c.Enc.Encode(payload); err != nil {
137151
if c.EncBuf.Flush() == nil {
@@ -142,6 +156,7 @@ func Encode(c *RPCServerCodec, payload interface{}) {
142156
}
143157
}
144158

159+
//Close ends the underlying server TCP session
145160
func (c *RPCServerCodec) Close() error {
146161
if c.Closed {
147162
return nil

0 commit comments

Comments
 (0)