diff options
Diffstat (limited to 'internal/ipc/server.go')
| -rw-r--r-- | internal/ipc/server.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/internal/ipc/server.go b/internal/ipc/server.go index 50dff7f..eea0ebb 100644 --- a/internal/ipc/server.go +++ b/internal/ipc/server.go @@ -66,16 +66,18 @@ func (h *Hub) unsubscribe(ch chan store.Summary) { // Server serves the daemon side of the mitmux control protocol. type Server struct { - db *store.Store - hub *Hub - repeater Repeater - intruder Intruder + db *store.Store + hub *Hub + repeater Repeater + intruder Intruder + proxyAddr string } // NewServer creates a control-protocol Server backed by db, broadcasting // through hub and sending Repeater/Intruder requests through rep. -func NewServer(db *store.Store, hub *Hub, rep Repeater) *Server { - s := &Server{db: db, hub: hub, repeater: rep} +// proxyAddr is reported back to clients via the "status" request. +func NewServer(db *store.Store, hub *Hub, rep Repeater, proxyAddr string) *Server { + s := &Server{db: db, hub: hub, repeater: rep, proxyAddr: proxyAddr} if in, ok := rep.(Intruder); ok { s.intruder = in } @@ -106,6 +108,14 @@ func (s *Server) handleConn(conn net.Conn) { } switch req.Type { + case "status": + count, err := s.db.Count() + if err != nil { + enc.Encode(Response{Type: "error", Error: err.Error()}) + continue + } + enc.Encode(Response{Type: "status", Status: &StatusMsg{ProxyAddr: s.proxyAddr, HistoryCount: count}}) + case "list": var entries []store.Summary var err error |