-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
130 lines (106 loc) · 3.99 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package ipc
import (
"fmt"
)
type IPCRequest struct {
MessageSignature []byte // The message signature, used to declare an ipcRequest
Header IPCHeader // The header - containing type and identifier
Message IPCMessage // The message
Timestamp int64 // Timestamp of the message
Checksum32 int // Checksum of the message byte data
}
type IPCHeader struct {
Identifier [4]byte // Identifier of the module - available from the IPCClient for qol purposes
MessageType byte // Type of the message
}
type IPCMessage struct {
Datatype DataType // Type of the data ("json", "string", "int", etc.)
Data []byte // The actual data
StringData string // String representation of the data if applicable
}
type IPCResponse struct {
Request IPCRequest // The request that was sent
Success bool // Was the request successful
Message string // Message from the server
Checksum32 int // Checksum of the message byte data
}
// GenericData is a generic map for data. It can be used to store any data type.
//
// Ex:
//
// var data GenericData = map[string]interface{}{"someKey": "someValue"}
// fmt.Println("Received data:", data["someKey"]) // Will print someValue
// GenericData is a generic map for data. It can be used to store any data type.
type GenericData map[string]interface{}
type Metadata struct {
Source string `json:"source"` // Source. Ex: sigma
Destination Destination `json:"destination"` // Destination. Ex: { name: database, info: "table=threat_intel" }
Method string `json:"method"` // Using HTTP verbs to differentiate between requests (ps: this got nothing to do with actual HTTP)
}
type Destination struct {
Object Object `json:"destination" yaml:"destination"` // should unmarsal as Destination
}
type GetJSON struct {
Metadata Metadata `json:"metadata"`
Description string `json:"description"`
}
type Object struct {
Id string `json:"id"`
Name string `json:"name"`
Database Database `json:"database"`
}
type Database struct {
Name string `json:"name"`
Table string `json:"table"`
RowID string `json:"row_id"` // Row ID - fetch anything after this ID
}
// ----------------------------
type MsgType int
type DataType int
const (
MSG_CONN = 0x01 // Connection message
MSG_ACK = 0x02 // Acknowledgement message
MSG_CONNACK = 0x03 // Connection acknowledgement message
MSG_MSG = 0x04 // Message
MSG_MSGACK = 0x05 // Message acknowledgement
MSG_PING = 0x08 // Ping message
MSG_PONG = 0x09 // Pong message
MSG_DISCONNECT = 0xD1 // Disconnect message
// Error message
// The sender is obviously still connected, but something went wrong and the message was not handled
MSG_ERROR = 0xEE
MSG_UNKNOWN = 0xFF // Unknown message - for signifying unknown type, maybe an error, but the receiver will try to wing it
)
const (
DATA_TEXT = 0x01 // Text data
DATA_INT = 0x02 // Integer data
DATA_JSON = 0x03 // JSON data (used for structured data)
DATA_YAML = 0x04 // YAML data (used for configuration files)
DATA_BIN = 0x05 // Binary data (such as images, files, etc.)
)
var MSGTYPE = map[string]byte{
"conn": byte(MSG_CONN),
"ack": byte(MSG_ACK),
"connack": byte(MSG_CONNACK),
"msg": byte(MSG_MSG),
"msgack": byte(MSG_MSGACK),
"ping": byte(MSG_PING),
"pong": byte(MSG_PONG),
"disconnect": byte(MSG_DISCONNECT),
"error": byte(MSG_ERROR),
"unknown": byte(MSG_UNKNOWN),
}
var IDENTIFIERS = map[string][4]byte{}
func (r *IPCRequest) Stringify() string {
h := fmt.Sprintf("HEADER:\n\tIdentifier: %v\nMessageType: %v\n", r.Header.Identifier, r.Header.MessageType)
// m := "MESSAGE:\n"
// for i, data := range r.Message.Data {
// m += fmt.Sprintf("\tData[%d]: %v\n", i, data)
// }
m := fmt.Sprintf("MESSAGE:\n\tData: %v\n\tStringData: %v\n", r.Message.Data, r.Message.StringData)
c := fmt.Sprintf("CHECKSUM: %v\n", r.Checksum32)
return h + m + c
}
func SetIdentifier(name string, id [4]byte) {
IDENTIFIERS[name] = id
}