Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize code structure for experiment replication #43

Merged
merged 35 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
db850be
feat: creating sample Go module
TechSolomon Nov 3, 2023
4d4b447
feat: example error handling
TechSolomon Nov 3, 2023
cfe708c
refactor: random example communication message
TechSolomon Nov 3, 2023
d5184a2
feat: example map data type (slice) & test cases
TechSolomon Nov 4, 2023
cded158
Template for suggested experimental expectations (#24)
TechSolomon Mar 2, 2024
034b7ba
Merge branch 'dev' of github.com:acep-uaf/data-diode into dev
TechSolomon Mar 5, 2024
867925f
fix: text cache source location
TechSolomon Mar 5, 2024
7676ab7
Delete `message` directory
TechSolomon Mar 5, 2024
b630302
Delete `example` directory
TechSolomon Mar 5, 2024
7d4f705
bump: latest Go milestone (minor release)
TechSolomon Mar 5, 2024
d25f5a9
Topic levels for MQTT (#27)
TechSolomon Mar 10, 2024
9a7f7f1
docs: finalize project directory structure
TechSolomon Mar 10, 2024
2c24f25
refactor: variables for testing content publisher
TechSolomon Mar 10, 2024
aadd7d9
feat: placeholder client + server (I/O)
TechSolomon Mar 12, 2024
56e17f6
refactor: data diode settings & connection constants
TechSolomon Mar 12, 2024
3cae110
refactor: application constants with minimal error handling
TechSolomon Mar 12, 2024
63f2ea8
fix: brange merge conflicts via command line
TechSolomon Mar 13, 2024
a9ba3e4
deps: remove outdated string metrics library
TechSolomon Mar 13, 2024
a09895f
docs: create B4-0144-355112.json (via Fend_B4_4.0.2.fw)
TechSolomon Mar 14, 2024
5010e61
refactor: diode test variables
TechSolomon Mar 14, 2024
16d57a0
docs: mock external API for schema validation
TechSolomon Mar 14, 2024
af9ef76
Mock system connection & message crafting (#34)
TechSolomon Mar 22, 2024
541088f
feat: MQTT test subscription + application (client/server)
TechSolomon Mar 22, 2024
88b9bf7
refactor: diode test command & server continuous stream
TechSolomon Mar 23, 2024
9d27891
Merge branch 'main' into dev
TechSolomon Mar 25, 2024
ffcf54d
fix: broken build with undefined import
TechSolomon Mar 25, 2024
bd39b60
refactor: draft goroutine for server connection(s)
TechSolomon Mar 25, 2024
bad9451
Merge remote-tracking branch 'origin/main' into dev
TechSolomon Mar 25, 2024
21d8678
nit: minor code format
TechSolomon Mar 25, 2024
16a479e
refactor: remove duplicate function contents
TechSolomon Mar 25, 2024
b033a84
Updated configuration flow of control (#38)
TechSolomon Apr 1, 2024
85e8c4e
docs: update main program directory name
TechSolomon Apr 1, 2024
e120498
Saturate components for testing diode system behavior (#42)
TechSolomon Apr 19, 2024
57b2f37
refactor: Dockerfile command, MQTT broker ports, & code comments
TechSolomon Apr 20, 2024
2936e11
Merge branch 'main' into dev
TechSolomon Apr 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ FROM golang:alpine
WORKDIR /cli
COPY . /cli
RUN CGO_ENABLED=0 GOOS=linux go build -o diode
CMD [ "./diode", "mqtt" ]
CMD [ "./diode", "diagnostics" ]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BIN_NAME=diode
BIN_VERSION=0.1.1
BIN_VERSION=0.1.2
BIN_DATE=$(shell date +%FT%T%z)

all: build
Expand Down
3 changes: 1 addition & 2 deletions config/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ mqtt:
outside:
server: "localhost"
port: 1883
prefix: "diode"
# Avoid namespace collisions
prefix: "diode" # Avoid namespace collisions
8 changes: 2 additions & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ services:
source: ./config/mosquitto.conf
target: /mosquitto/config/mosquitto.conf
ports:
- target: 1883
published: 1883
- target: 9001
published: 9001
protocol: tcp
mode: host
mqtt-client:
Expand All @@ -20,7 +20,3 @@ services:
container_name: sample-client-connection
depends_on:
- mqtt-broker

volumes:
data:
name: "mqtt-benchmark-data"
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ go 1.22

require (
github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/olekukonko/tablewriter v0.0.5
github.com/urfave/cli/v2 v2.27.1
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
)
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQ
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
11 changes: 4 additions & 7 deletions insights/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package analysis
import (
"crypto/sha256"
"io"
"math/rand"
"net/http"
"time"
)

func Pong() bool {
Expand All @@ -23,6 +21,10 @@ func Pong() bool {
return true
}

func Saturate() {
println(">> Data Diode Components")
}

func Checksum() [32]byte {
location := "https://www.gutenberg.org/cache/epub/84/pg84.txt"

Expand All @@ -44,8 +46,3 @@ func Checksum() [32]byte {

return hash
}

func Value() int {
randGenerator := rand.New(rand.NewSource(time.Now().UnixNano()))
return randGenerator.Intn(100)
}
38 changes: 0 additions & 38 deletions insights/experiment.go

This file was deleted.

2 changes: 1 addition & 1 deletion insights/observability.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

START=`date +%Y-%m-%d-%k:%m:%S`
COLLECTION=`date +%Y-%m-%d`
LOGFILE="insights/ACEP_CAMIO_SEDOID_RESULTS-${COLLECTION}.txt"
LOGFILE="insights/DIODE_RESULTS-${COLLECTION}.txt"

function log() {
echo "diode: $@"
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
SemVer string
BuildInfo string
ConfigSettings = "config/settings.yaml"
InputTextFile = "docs/example.txt"
)

type Configuration struct {
Expand Down Expand Up @@ -141,6 +140,7 @@ func main() {
Usage: "System benchmark analysis + report performance metrics",
Action: func(bCtx *cli.Context) error {
fmt.Println("----- BENCHMARKS -----")
analysis.Saturate()
return nil
},
},
Expand Down
57 changes: 21 additions & 36 deletions utility/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"fmt"
"log"
"net"
"time"
)

const (
ACKNOWLEDGEMENT = "OK\r\n"
CONN_TYPE = "tcp"
MAX_ATTEMPTS = 2
CHUNK_SIZE = 1460 // ? Characters
SAMPLE = 10240 // 10 Kbytes
CHUNK_SIZE = 1460
SAMPLE = 10240
)

func SendMessage(input string, client string) {
Expand Down Expand Up @@ -45,11 +43,6 @@ func SendMessage(input string, client string) {
}

func StartPlaceholderClient(host string, port int) {

for i := 1; i <= MAX_ATTEMPTS; i++ {
fmt.Printf(">> [%d of %d] Dialing host %s on port %d via %s...\n", i, MAX_ATTEMPTS, host, port, CONN_TYPE)
}

conn, err := net.Dial(CONN_TYPE, fmt.Sprintf("%s:%d", host, port))

if err != nil {
Expand All @@ -73,41 +66,33 @@ func StartPlaceholderClient(host string, port int) {
fmt.Printf(">> Server response: %s\n", string(buffer[:bytesRead]))
}

func ProcessMessage(message string, conn net.Conn) bool {
for try := 1; try <= MAX_ATTEMPTS; try++ {
if len(message) > CHUNK_SIZE {
index := 0
func ProcessMessage(message string, conn net.Conn) {
if len(message) > CHUNK_SIZE {
index := 0

for index < len(message) {
chunk := message[index : index+CHUNK_SIZE]
for index < len(message) {
chunk := message[index : index+CHUNK_SIZE]

_, err := conn.Write([]byte(chunk))
if err != nil {
fmt.Println(">> [!] Error sending data: ", err)
return true
}
_, err := conn.Write([]byte(chunk))
if err != nil {
fmt.Println(">> [!] Error sending data: ", err)
}

response := make([]byte, 4)
_, err = conn.Read(response)
if err != nil {
fmt.Println(">> [!] Error receiving ACK: ", err)
return true
}
response := make([]byte, 4)
_, err = conn.Read(response)
if err != nil {
fmt.Println(">> [!] Error receiving ACK: ", err)
}

if string(response) != ACKNOWLEDGEMENT {
fmt.Println(">> [?] Invalid ACK received.")
return true
}
if string(response) != ACKNOWLEDGEMENT {
fmt.Println(">> [?] Invalid ACK received.")
}

fmt.Printf(">> Successfully sent message to diode: %s\n", chunk)
fmt.Printf(">> Successfully sent message to diode: %s\n", chunk)

index += CHUNK_SIZE
}
index += CHUNK_SIZE
}

time.Sleep(1 * time.Second)
}
return false
}

func StartPlaceholderServer(host string, port int) {
Expand Down
35 changes: 22 additions & 13 deletions utility/application_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package utility

import "testing"
import (
"net"
"testing"
)

func TestClient(t *testing.T) {
got := "server"
want := "client"

if got != want {
t.Errorf("got %q, want %q", got, want)
func TestRecieveMessage(t *testing.T) {
serverMock, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("[!] Failed to start the mock server: %v", err)
}
}
defer serverMock.Close()

serverMockAddress := serverMock.Addr().String()

func TestServer(t *testing.T) {
got := "client"
want := "server"
contents := make(chan string)
go func() {
err := RecieveMessage(serverMockAddress, contents)
if err != nil {
t.Errorf("[?] Returned an error: %v", err)
}
}()

if got != want {
t.Errorf("got %q, want %q", got, want)
conn, err := net.Dial("tcp", serverMockAddress)
if err != nil {
t.Fatalf("[!] Failed to connect to the mock server: %v", err)
}
defer conn.Close()
}
4 changes: 1 addition & 3 deletions utility/republisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ func EncapsulatePayload(message string) string {
}

func UnencapsulatePayload(message string) string {
// TODO: Test case(s) for various message lengths and content.

decoded, err := base64.StdEncoding.DecodeString(message)
if err != nil {
fmt.Println(">> [!] Error decoding the message: ", err)
Expand All @@ -141,7 +139,7 @@ func PublishPayload(server string, port int, topic string, message string) {
}

func MakeTimestamp() int64 {
return time.Now().UnixMilli()
return time.Now().UnixMicro()
}

func Verification(data string) string {
Expand Down