diff options
Diffstat (limited to 'internal/ipc/ipc.go')
| -rw-r--r-- | internal/ipc/ipc.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/internal/ipc/ipc.go b/internal/ipc/ipc.go index 03a4bc7..d295238 100644 --- a/internal/ipc/ipc.go +++ b/internal/ipc/ipc.go @@ -48,11 +48,12 @@ type Request struct { // Response is sent by the daemon to a client. type Response struct { - Type string `json:"type"` // "list", "get", "new", "repeat", "rules", "intrude_result", "intrude_done", or "error" + Type string `json:"type"` // "list", "get", "new", "repeat", "rules", "intrude_result", "intrude_done", "status", or "error" Entries []store.Summary `json:"entries,omitempty"` // for "list" Detail *EntryDetail `json:"detail,omitempty"` // for "get" and "repeat" New *store.Summary `json:"new,omitempty"` // for "new" (subscribe push) Rules []rules.Rule `json:"rules,omitempty"` // for "rules" + Status *StatusMsg `json:"status,omitempty"` // for "status" // For "intrude_result": one completed attack request. IntrudeResult *IntrudeResultMsg `json:"intrude_result,omitempty"` @@ -60,6 +61,12 @@ type Response struct { Error string `json:"error,omitempty"` } +// StatusMsg is basic daemon info for a TUI status bar. +type StatusMsg struct { + ProxyAddr string `json:"proxy_addr"` + HistoryCount int64 `json:"history_count"` +} + // IntrudeResultMsg is one completed Intruder attack request. type IntrudeResultMsg struct { Position int `json:"position"` @@ -110,6 +117,23 @@ func (c *Client) Close() error { return c.conn.Close() } +// Status returns basic daemon info for a status bar. +func (c *Client) Status() (*StatusMsg, error) { + c.mu.Lock() + defer c.mu.Unlock() + if err := c.enc.Encode(Request{Type: "status"}); err != nil { + return nil, err + } + var resp Response + if err := c.dec.Decode(&resp); err != nil { + return nil, err + } + if resp.Type == "error" { + return nil, errors.New(resp.Error) + } + return resp.Status, nil +} + // List returns up to limit history summaries older than beforeID (0 for // the most recent), newest first. func (c *Client) List(limit int, beforeID int64) ([]store.Summary, error) { |