Code Monkey home page Code Monkey logo

Comments (2)

influx6 avatar influx6 commented on June 12, 2024

We will need to define consistent message string or integer values(preferable) of a message type which will be sent over the wire when requesting sessions or events data from the websocket API.

Proposal

Below is defined a set of possible message int types usable for the socket message requests and response.

type MessageType int
  • Request Message Type values
    (Sent by Client and responded to by backend for sessions/events)
FETCH_SESSIONS = 1
FETCH_SESSIONS_REPLY=2
FETCH_EVENTS = 3
FETCH_EVENTS_REPLY=4
  • Update Message Type values
    (Sent down from backend with new sessions/events update data)
NEW_SESSIONS=5
NEW_EVENTS=6

Message Format

I reason that, to allow a consistent message type which must be used to define request and response sent and received, we need to at least use the structure as below:

type Message struct{
  Type MessageType `json:"type"`
  Payload interface{} `json:"payload"`
}
  • MessageType is an int type which is used to represent the above mentioned message types.

  • Payload: is a generic type which only ever be used when responding from the backend to any request, if a payload is sent along with a request Message then it will be discarded and ignored, as we only want a get/retrieve style requests for the websocket connection API.

Response

All response for the request and data delivered to the client based on internal backend operations will take the form:

type Event struct{
	Sensor      string                 `json:"sensor"`
	Date        time.Time              `json:"date"`
	Started     time.Time              `json:"started,omitempty"`
	Ended       time.Time              `json:"ended,omitempty"`
	Token       string                 `json:"token,omitempty"`
	Location    string                 `json:"location,omitempty"`
	Category    string                 `json:"category"`
	HostAddr    string                 `json:"host_addr"`
	LocalAddr   string                 `json:"local_addr"`
	Type        EventType              `json:"event_type"`
	Data        interface{}            `json:"data"`
	Details     map[string]interface{} `json:"details"`
	SessionID   string                 `json:"session_id,omitempty"`
	ContainerID string                 `json:"container_id,omitempty"`
}

// Possible message sent over the wire.
var newSessions = Message{Type: NewSessions, Payload: []Event{}}

from honeytrap.

influx6 avatar influx6 commented on June 12, 2024

I believe we also need a MessageType for error response as we expect we may recieved invalid requests from the client.

ErrorResponse = 7

Which should received a payload of the follow type:

type ErrorPayload struct{
  Request MessageType `json:"request"`
  Error string `json:"error"`
}

from honeytrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.