Proper project structure and architecture implementation

This commit is contained in:
Marcel M. Otte 2023-01-02 20:02:50 +01:00
parent de7306b8f0
commit 54ea40d3f1
14 changed files with 213 additions and 47 deletions

View File

@ -1,8 +1,11 @@
package ppf
import "fyne.io/fyne/v2/widget"
import (
"fyne.io/fyne/v2/widget"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
)
func CreateView(field Field) *widget.BaseWidget {
func CreateView(field protocol.Field) *widget.BaseWidget {
return nil
}

5
go.mod
View File

@ -2,7 +2,10 @@ module gitea.mmo.to/ProtocolPacketForger/ppf
go 1.19
require fyne.io/fyne/v2 v2.2.4
require (
fyne.io/fyne/v2 v2.2.4
github.com/spf13/viper v1.10.1
)
require (
fyne.io/systray v1.10.1-0.20220621085403-9a2652634e93 // indirect

View File

@ -1,3 +1,10 @@
go 1.19
use .
//use protocol
//use protocolctl
//use packet
//use packetctl
//use dop
//use dopctl

View File

@ -1,2 +1,16 @@
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

0
packet/fieldvalue.go Normal file
View File

0
packet/packet.go Normal file
View File

0
packetctl/packetctl.go Normal file
View File

View File

@ -0,0 +1,6 @@
package protocol
type DefaultFieldValue struct {
FieldRef string
Value string
}

6
protocol/defaultvalue.go Normal file
View File

@ -0,0 +1,6 @@
package protocol
type DefaultValue struct {
Desc string
FieldValues []DefaultFieldValue
}

16
protocol/dopmeta.go Normal file
View File

@ -0,0 +1,16 @@
package protocol
const DOPVersion string = "1.0"
type DOPMeta struct {
// DOP metadata version 1.0
DOPVersion string
Name string
Version string
TCPIPLayer uint
OSILayer uint
ExtensionTo string
Description string
RequiredJSFunctions []string
LowerLayerIdentification map[string]string
}

11
protocol/field.go Normal file
View File

@ -0,0 +1,11 @@
package protocol
type Field struct {
Name string // Name of the Field
Desc string // Lengthy description
Regex string // Regex to recognize values
Size uint // Size in bits!
SubFields []Field // Possible sub-fields
Optional bool // Is this field required?
Payload bool // Is this field the payload or next protocol level?
}

8
protocol/protocol.go Normal file
View File

@ -0,0 +1,8 @@
package protocol
type ProtocolStructure struct {
Metadata DOPMeta
Structure []Field
DefaultValues []DefaultValue
JavaScript string
}

130
protocolctl/protocolctl.go Normal file
View File

@ -0,0 +1,130 @@
package protocolctl
import (
"encoding/json"
"io/fs"
"os"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
)
func NewProtocolStructure() *protocol.ProtocolStructure {
p := protocol.ProtocolStructure{}
return &p
}
func UpdateMetaData(
prot *protocol.ProtocolStructure,
name string,
version string,
tcpiplayer uint,
osilayer uint,
extensionTo string,
desc string,
requiredJSfunctions []string,
lowerLayerIdent map[string]string,
) {
prot.Metadata.Name = name
prot.Metadata.Description = desc
prot.Metadata.ExtensionTo = extensionTo
prot.Metadata.Version = version
prot.Metadata.OSILayer = osilayer
prot.Metadata.TCPIPLayer = tcpiplayer
prot.Metadata.RequiredJSFunctions = requiredJSfunctions
prot.Metadata.LowerLayerIdentification = lowerLayerIdent
}
func NewField(
name string,
desc string,
regex string,
size uint,
subfields []protocol.Field,
optional bool,
payload bool,
) *protocol.Field {
f := protocol.Field{
Name: name,
Desc: desc,
Regex: regex,
Size: size,
SubFields: subfields,
Optional: optional,
Payload: payload,
}
return &f
}
func AppendField(prot *protocol.ProtocolStructure, field *protocol.Field) {
prot.Structure = append(prot.Structure, *field)
}
func UpdateFieldByRef(prot *protocol.ProtocolStructure, field *protocol.Field) {
for _, f := range prot.Structure {
if f.Name == field.Name {
f.Desc = field.Desc
f.Optional = field.Optional
f.Payload = field.Payload
f.Regex = field.Regex
f.Size = field.Size
f.SubFields = field.SubFields
}
}
}
func UpdateFieldByElement(prot *protocol.ProtocolStructure, element int, field *protocol.Field) {
for i, f := range prot.Structure {
if i == element {
f.Desc = field.Desc
f.Optional = field.Optional
f.Payload = field.Payload
f.Regex = field.Regex
f.Size = field.Size
f.SubFields = field.SubFields
}
}
}
func RemoveFieldByRef(prot *protocol.ProtocolStructure, field *protocol.Field) {
element := -1
for i, f := range prot.Structure {
if f.Name == field.Name {
element = i
}
}
if element == -1 {
return
}
RemoveFieldByElement(prot, element)
}
func RemoveFieldByElement(prot *protocol.ProtocolStructure, field int) {
ret := make([]protocol.Field, 0)
ret = append(ret, prot.Structure[:field]...)
ret = append(ret, prot.Structure[field+1:]...)
prot.Structure = ret
}
func Load(prot *protocol.ProtocolStructure, path string) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
err = json.Unmarshal(data, prot)
return err
}
func LoadNew(path string) (*protocol.ProtocolStructure, error) {
prot := NewProtocolStructure()
err := Load(prot, path)
return prot, err
}
func Save(prot *protocol.ProtocolStructure, path string) error {
data, err := json.Marshal(*prot)
if err != nil {
return err
}
err = os.WriteFile(path, data, fs.ModeAppend)
return err
}

View File

@ -1,46 +1,8 @@
package ppf
type Field struct {
Name string // Name of the Field
Desc string // Lengthy description
Regex string // Regex to recognize values
Size uint // Size in bits!
SubFields []Field // Possible sub-fields
Optional bool // Is this field required?
Payload bool // Is this field the payload or next protocol level?
PredefinedValues []PredefinedFieldValue // Collection of predefined field values
}
type PredefinedFieldValue struct {
Desc string
FieldValues []FieldValue
}
type FieldValue struct {
FieldRef *Field
Value string
}
type ProtocolStructure struct {
Metadata DOPMetadata
Structure []Field
}
type DOPMetadata struct {
DOPVersion string
Name string
Version string
TCPIPLayer uint
OSILayer uint
ExtensionTo string
Description string
RequiredJSFunctions []string
LowerLayerIdentification map[string]string
}
type DataModel struct {
Name string // User defined name of his current work (filename later)
Protocols []ProtocolStructure // List of protocols in order of the stack
Data []FieldValue // Data of the fields of all protocols
ProtocolCreation bool
}
//type DataModel struct {
// Name string // User defined name of his current work (filename later)
// Protocols []ProtocolStructure // List of protocols in order of the stack
// Data []FieldValue // Data of the fields of all protocols
// ProtocolCreation bool
//}