Skip to content

Commit

Permalink
pkg/rpcserver: capitalize external interface methods
Browse files Browse the repository at this point in the history
Make it explicit which methods of Runner refer to its implementation and
which are supposed to be invoked by its users.
  • Loading branch information
a-nogikh committed Jul 4, 2024
1 parent 891bf15 commit ecfab6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
26 changes: 13 additions & 13 deletions pkg/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,20 @@ func (serv *Server) MachineInfo(name string) []byte {
serv.mu.Lock()
runner := serv.runners[name]
serv.mu.Unlock()
if runner == nil || !runner.alive() {
if runner == nil || !runner.Alive() {
return []byte("VM is not alive")
}
return runner.getMachineInfo()
return runner.MachineInfo()
}

func (serv *Server) RunnerStatus(name string) []byte {
serv.mu.Lock()
runner := serv.runners[name]
serv.mu.Unlock()
if runner == nil || !runner.alive() {
if runner == nil || !runner.Alive() {
return []byte("VM is not alive")
}
return runner.queryStatus()
return runner.QueryStatus()
}

func (serv *Server) handleConn(conn *flatrpc.Conn) {
Expand Down Expand Up @@ -259,7 +259,7 @@ func (serv *Server) handleConn(conn *flatrpc.Conn) {
opts.Features = serv.cfg.Features
}

err = runner.handshake(conn, opts)
err = runner.Handshake(conn, opts)
if err != nil {
log.Logf(1, "%v", err)
return
Expand All @@ -270,7 +270,7 @@ func (serv *Server) handleConn(conn *flatrpc.Conn) {
serv.mu.Unlock()

if serv.triagedCorpus.Load() {
if err := runner.sendCorpusTriaged(); err != nil {
if err := runner.SendCorpusTriaged(); err != nil {
log.Logf(2, "%v", err)
return
}
Expand Down Expand Up @@ -333,7 +333,7 @@ func (serv *Server) connectionLoop(runner *Runner) error {
// buffer too much (we don't want to grow it larger than what will be needed
// to send programs).
n := min(len(maxSignal), 50000)
if err := runner.sendSignalUpdate(maxSignal[:n]); err != nil {
if err := runner.SendSignalUpdate(maxSignal[:n]); err != nil {
return err
}
maxSignal = maxSignal[n:]
Expand All @@ -343,7 +343,7 @@ func (serv *Server) connectionLoop(runner *Runner) error {
serv.StatNumFuzzing.Add(1)
defer serv.StatNumFuzzing.Add(-1)

return runner.connectionLoop()
return runner.ConnectionLoop()
}

func checkRevisions(a *flatrpc.ConnectRequest, target *prog.Target) {
Expand Down Expand Up @@ -462,7 +462,7 @@ func (serv *Server) StopFuzzing(name string) {
runner := serv.runners[name]
serv.info[name] = VMState{StateStopping, time.Now()}
serv.mu.Unlock()
runner.stop()
runner.Stop()
}

func (serv *Server) ShutdownInstance(name string, crashed bool) ([]ExecRecord, []byte) {
Expand All @@ -471,20 +471,20 @@ func (serv *Server) ShutdownInstance(name string, crashed bool) ([]ExecRecord, [
delete(serv.runners, name)
serv.info[name] = VMState{StateOffline, time.Now()}
serv.mu.Unlock()
return runner.shutdown(crashed), runner.getMachineInfo()
return runner.Shutdown(crashed), runner.MachineInfo()
}

func (serv *Server) DistributeSignalDelta(plus signal.Signal) {
plusRaw := plus.ToRaw()
serv.foreachRunnerAsync(func(runner *Runner) {
runner.sendSignalUpdate(plusRaw)
runner.SendSignalUpdate(plusRaw)
})
}

func (serv *Server) TriagedCorpus() {
serv.triagedCorpus.Store(true)
serv.foreachRunnerAsync(func(runner *Runner) {
runner.sendCorpusTriaged()
runner.SendCorpusTriaged()
})
}

Expand All @@ -495,7 +495,7 @@ func (serv *Server) foreachRunnerAsync(fn func(runner *Runner)) {
serv.mu.Lock()
defer serv.mu.Unlock()
for _, runner := range serv.runners {
if runner.alive() {
if runner.Alive() {
go fn(runner)
}
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/rpcserver/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type handshakeResult struct {
Canonicalizer *cover.CanonicalizerInstance
}

func (runner *Runner) handshake(conn *flatrpc.Conn, cfg *handshakeConfig) error {
func (runner *Runner) Handshake(conn *flatrpc.Conn, cfg *handshakeConfig) error {
connectReply := &flatrpc.ConnectReply{
Debug: runner.debug,
Cover: runner.cover,
Expand Down Expand Up @@ -118,7 +118,7 @@ func (runner *Runner) handshake(conn *flatrpc.Conn, cfg *handshakeConfig) error
return nil
}

func (runner *Runner) connectionLoop() error {
func (runner *Runner) ConnectionLoop() error {
runner.mu.Lock()
stopped := runner.stopped
if !stopped {
Expand Down Expand Up @@ -390,7 +390,7 @@ func (runner *Runner) convertCallInfo(call *flatrpc.CallInfo) {
}
}

func (runner *Runner) sendSignalUpdate(plus []uint64) error {
func (runner *Runner) SendSignalUpdate(plus []uint64) error {
msg := &flatrpc.HostMessage{
Msg: &flatrpc.HostMessages{
Type: flatrpc.HostMessagesRawSignalUpdate,
Expand All @@ -402,7 +402,7 @@ func (runner *Runner) sendSignalUpdate(plus []uint64) error {
return flatrpc.Send(runner.conn, msg)
}

func (runner *Runner) sendCorpusTriaged() error {
func (runner *Runner) SendCorpusTriaged() error {
msg := &flatrpc.HostMessage{
Msg: &flatrpc.HostMessages{
Type: flatrpc.HostMessagesRawCorpusTriaged,
Expand All @@ -412,7 +412,7 @@ func (runner *Runner) sendCorpusTriaged() error {
return flatrpc.Send(runner.conn, msg)
}

func (runner *Runner) stop() {
func (runner *Runner) Stop() {
runner.mu.Lock()
runner.stopped = true
conn := runner.conn
Expand All @@ -422,7 +422,7 @@ func (runner *Runner) stop() {
}
}

func (runner *Runner) shutdown(crashed bool) []ExecRecord {
func (runner *Runner) Shutdown(crashed bool) []ExecRecord {
runner.mu.Lock()
runner.stopped = true
finished := runner.finished
Expand All @@ -442,13 +442,13 @@ func (runner *Runner) shutdown(crashed bool) []ExecRecord {
return runner.lastExec.Collect()
}

func (runner *Runner) getMachineInfo() []byte {
func (runner *Runner) MachineInfo() []byte {
runner.mu.Lock()
defer runner.mu.Unlock()
return runner.machineInfo
}

func (runner *Runner) queryStatus() []byte {
func (runner *Runner) QueryStatus() []byte {
resc := make(chan []byte, 1)
timeout := time.After(time.Minute)
select {
Expand All @@ -464,7 +464,7 @@ func (runner *Runner) queryStatus() []byte {
}
}

func (runner *Runner) alive() bool {
func (runner *Runner) Alive() bool {
runner.mu.Lock()
defer runner.mu.Unlock()
return runner.conn != nil && !runner.stopped
Expand Down

0 comments on commit ecfab6a

Please sign in to comment.