mirror of
https://github.com/safing/portmaster
synced 2025-04-16 17:09:09 +00:00
* Move portbase into monorepo * Add new simple module mgr * [WIP] Switch to new simple module mgr * Add StateMgr and more worker variants * [WIP] Switch more modules * [WIP] Switch more modules * [WIP] swtich more modules * [WIP] switch all SPN modules * [WIP] switch all service modules * [WIP] Convert all workers to the new module system * [WIP] add new task system to module manager * [WIP] Add second take for scheduling workers * [WIP] Add FIXME for bugs in new scheduler * [WIP] Add minor improvements to scheduler * [WIP] Add new worker scheduler * [WIP] Fix more bug related to new module system * [WIP] Fix start handing of the new module system * [WIP] Improve startup process * [WIP] Fix minor issues * [WIP] Fix missing subsystem in settings * [WIP] Initialize managers in constructor * [WIP] Move module event initialization to constrictors * [WIP] Fix setting for enabling and disabling the SPN module * [WIP] Move API registeration into module construction * [WIP] Update states mgr for all modules * [WIP] Add CmdLine operation support * Add state helper methods to module group and instance * Add notification and module status handling to status package * Fix starting issues * Remove pilot widget and update security lock to new status data * Remove debug logs * Improve http server shutdown * Add workaround for cleanly shutting down firewall+netquery * Improve logging * Add syncing states with notifications for new module system * Improve starting, stopping, shutdown; resolve FIXMEs/TODOs * [WIP] Fix most unit tests * Review new module system and fix minor issues * Push shutdown and restart events again via API * Set sleep mode via interface * Update example/template module * [WIP] Fix spn/cabin unit test * Remove deprecated UI elements * Make log output more similar for the logging transition phase * Switch spn hub and observer cmds to new module system * Fix log sources * Make worker mgr less error prone * Fix tests and minor issues * Fix observation hub * Improve shutdown and restart handling * Split up big connection.go source file * Move varint and dsd packages to structures repo * Improve expansion test * Fix linter warnings * Fix interception module on windows * Fix linter errors --------- Co-authored-by: Vladimir Stoilov <vladimir@safing.io>
145 lines
3 KiB
Go
145 lines
3 KiB
Go
package record
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// GenCodeSize returns the size of the gencode marshalled byte slice.
|
|
func (m *Meta) GenCodeSize() (s int) {
|
|
s += 34
|
|
return
|
|
}
|
|
|
|
// GenCodeMarshal gencode marshalls Meta into the given byte array, or a new one if its too small.
|
|
func (m *Meta) GenCodeMarshal(buf []byte) ([]byte, error) {
|
|
size := m.GenCodeSize()
|
|
{
|
|
if cap(buf) >= size {
|
|
buf = buf[:size]
|
|
} else {
|
|
buf = make([]byte, size)
|
|
}
|
|
}
|
|
i := uint64(0)
|
|
|
|
{
|
|
|
|
buf[0+0] = byte(m.Created >> 0)
|
|
|
|
buf[1+0] = byte(m.Created >> 8)
|
|
|
|
buf[2+0] = byte(m.Created >> 16)
|
|
|
|
buf[3+0] = byte(m.Created >> 24)
|
|
|
|
buf[4+0] = byte(m.Created >> 32)
|
|
|
|
buf[5+0] = byte(m.Created >> 40)
|
|
|
|
buf[6+0] = byte(m.Created >> 48)
|
|
|
|
buf[7+0] = byte(m.Created >> 56)
|
|
|
|
}
|
|
{
|
|
|
|
buf[0+8] = byte(m.Modified >> 0)
|
|
|
|
buf[1+8] = byte(m.Modified >> 8)
|
|
|
|
buf[2+8] = byte(m.Modified >> 16)
|
|
|
|
buf[3+8] = byte(m.Modified >> 24)
|
|
|
|
buf[4+8] = byte(m.Modified >> 32)
|
|
|
|
buf[5+8] = byte(m.Modified >> 40)
|
|
|
|
buf[6+8] = byte(m.Modified >> 48)
|
|
|
|
buf[7+8] = byte(m.Modified >> 56)
|
|
|
|
}
|
|
{
|
|
|
|
buf[0+16] = byte(m.Expires >> 0)
|
|
|
|
buf[1+16] = byte(m.Expires >> 8)
|
|
|
|
buf[2+16] = byte(m.Expires >> 16)
|
|
|
|
buf[3+16] = byte(m.Expires >> 24)
|
|
|
|
buf[4+16] = byte(m.Expires >> 32)
|
|
|
|
buf[5+16] = byte(m.Expires >> 40)
|
|
|
|
buf[6+16] = byte(m.Expires >> 48)
|
|
|
|
buf[7+16] = byte(m.Expires >> 56)
|
|
|
|
}
|
|
{
|
|
|
|
buf[0+24] = byte(m.Deleted >> 0)
|
|
|
|
buf[1+24] = byte(m.Deleted >> 8)
|
|
|
|
buf[2+24] = byte(m.Deleted >> 16)
|
|
|
|
buf[3+24] = byte(m.Deleted >> 24)
|
|
|
|
buf[4+24] = byte(m.Deleted >> 32)
|
|
|
|
buf[5+24] = byte(m.Deleted >> 40)
|
|
|
|
buf[6+24] = byte(m.Deleted >> 48)
|
|
|
|
buf[7+24] = byte(m.Deleted >> 56)
|
|
|
|
}
|
|
{
|
|
if m.secret {
|
|
buf[32] = 1
|
|
} else {
|
|
buf[32] = 0
|
|
}
|
|
}
|
|
{
|
|
if m.cronjewel {
|
|
buf[33] = 1
|
|
} else {
|
|
buf[33] = 0
|
|
}
|
|
}
|
|
return buf[:i+34], nil
|
|
}
|
|
|
|
// GenCodeUnmarshal gencode unmarshalls Meta and returns the bytes read.
|
|
func (m *Meta) GenCodeUnmarshal(buf []byte) (uint64, error) {
|
|
if len(buf) < m.GenCodeSize() {
|
|
return 0, fmt.Errorf("insufficient data: got %d out of %d bytes", len(buf), m.GenCodeSize())
|
|
}
|
|
|
|
i := uint64(0)
|
|
|
|
{
|
|
m.Created = 0 | (int64(buf[0+0]) << 0) | (int64(buf[1+0]) << 8) | (int64(buf[2+0]) << 16) | (int64(buf[3+0]) << 24) | (int64(buf[4+0]) << 32) | (int64(buf[5+0]) << 40) | (int64(buf[6+0]) << 48) | (int64(buf[7+0]) << 56)
|
|
}
|
|
{
|
|
m.Modified = 0 | (int64(buf[0+8]) << 0) | (int64(buf[1+8]) << 8) | (int64(buf[2+8]) << 16) | (int64(buf[3+8]) << 24) | (int64(buf[4+8]) << 32) | (int64(buf[5+8]) << 40) | (int64(buf[6+8]) << 48) | (int64(buf[7+8]) << 56)
|
|
}
|
|
{
|
|
m.Expires = 0 | (int64(buf[0+16]) << 0) | (int64(buf[1+16]) << 8) | (int64(buf[2+16]) << 16) | (int64(buf[3+16]) << 24) | (int64(buf[4+16]) << 32) | (int64(buf[5+16]) << 40) | (int64(buf[6+16]) << 48) | (int64(buf[7+16]) << 56)
|
|
}
|
|
{
|
|
m.Deleted = 0 | (int64(buf[0+24]) << 0) | (int64(buf[1+24]) << 8) | (int64(buf[2+24]) << 16) | (int64(buf[3+24]) << 24) | (int64(buf[4+24]) << 32) | (int64(buf[5+24]) << 40) | (int64(buf[6+24]) << 48) | (int64(buf[7+24]) << 56)
|
|
}
|
|
{
|
|
m.secret = buf[32] == 1
|
|
}
|
|
{
|
|
m.cronjewel = buf[33] == 1
|
|
}
|
|
return i + 34, nil
|
|
}
|