Skip to content

Commit

Permalink
Finalize code structure for experiment replication (#43)
Browse files Browse the repository at this point in the history
* refactor: entry point for main application, build information, & testing

* feat: split input & output metadata via project settings

* fix: repackaged JSON object contents + diode metadata

* docs: update main program directory name

* Saturate components for testing diode system behavior (#42)
  • Loading branch information
TechSolomon authored Apr 20, 2024
1 parent c10a4ba commit f036b1d
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 126 deletions.
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

0 comments on commit f036b1d

Please sign in to comment.