From f626f0ff2e8346e5bc6e820534d613b7f6415628 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 18 Aug 2025 00:05:45 -0500 Subject: [PATCH] fixup --- event.gui.pb.go | 394 +++++++++++++++++++++++++++++++++++ event.marshal.pb.go | 56 +++++ event.pb.go | 470 ++++++++++++++++++++++++++++++++++++++++++ event.sort.pb.go | 200 ++++++++++++++++++ go.mod | 48 +++++ go.sum | 92 +++++++++ portmap.gui.pb.go | 408 ++++++++++++++++++++++++++++++++++++ portmap.marshal.pb.go | 56 +++++ portmap.pb.go | 294 ++++++++++++++++++++++++++ portmap.sort.pb.go | 203 ++++++++++++++++++ 10 files changed, 2221 insertions(+) create mode 100644 event.gui.pb.go create mode 100644 event.marshal.pb.go create mode 100644 event.pb.go create mode 100644 event.sort.pb.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 portmap.gui.pb.go create mode 100644 portmap.marshal.pb.go create mode 100644 portmap.pb.go create mode 100644 portmap.sort.pb.go diff --git a/event.gui.pb.go b/event.gui.pb.go new file mode 100644 index 0000000..9544a2a --- /dev/null +++ b/event.gui.pb.go @@ -0,0 +1,394 @@ +// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. +// This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC +// go install go.wit.com/apps/autogenpb@latest +// +// define which structs (messages) you want to use in the .proto file +// Then sort.pb.go and marshal.pb.go files are autogenerated +// +// autogenpb uses it and has an example .proto file with instructions +// + +package main + +import ( + "time" + + "github.com/google/uuid" + "go.wit.com/gui" + "go.wit.com/lib/protobuf/guipb" + "go.wit.com/log" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" +) + +// START GUI + +func (x *Events) NewTable(title string) *EventsTable { + t := new(EventsTable) + t.x = x + pb := new(guipb.Table) + pb.Title = title + t.pb = pb + return t +} + +func (t *EventsTable) AddStringFunc(title string, f func(*Event) string) *EventStringFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(EventStringFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.stringFuncs = append(t.stringFuncs, sf) + return sf +} + +func (t *EventsTable) AddButtonFunc(title string, f func(*Event) string) *EventButtonFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(EventButtonFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.buttonFuncs = append(t.buttonFuncs, sf) + return sf +} + +func (t *EventsTable) AddIntFunc(title string, f func(*Event) int) *EventIntFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(EventIntFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.intFuncs = append(t.intFuncs, sf) + return sf +} + +func (t *EventsTable) AddTimeFunc(title string, f func(*Event) time.Time) *EventTimeFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(EventTimeFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.timeFuncs = append(t.timeFuncs, sf) + return sf +} + +func (sf *EventStringFunc) SetTitle(title string) { + sf.title = title +} +func (sf *EventIntFunc) SetTitle(title string) { + sf.title = title +} +func (sf *EventTimeFunc) SetTitle(title string) { + sf.title = title +} + +func (mt *EventsTable) SetParent(p *gui.Node) { + mt.parent = p +} + +func (mt *EventsTable) ShowTable() { + // log.Info("ShowTable() SENDING TO GUI") + mt.MakeTable() + mt.parent.ShowTable(mt.pb) +} + +type EventStringFunc struct { + title string + f func(*Event) string + Custom func(*Event) + order int +} + +type EventButtonFunc struct { + title string + f func(*Event) string + Custom func(*Event) + order int +} + +type EventIntFunc struct { + title string + f func(*Event) int + Custom func(*Event) + order int +} + +type EventTimeFunc struct { + title string + f func(*Event) time.Time + Custom func(*Event) + order int +} + +type EventsTable struct { + pb *guipb.Table + parent *gui.Node + x *Events + hostnames []string + stringFuncs []*EventStringFunc + intFuncs []*EventIntFunc + timeFuncs []*EventTimeFunc + buttonFuncs []*EventButtonFunc + CustomFunc func(*Event) + order int +} + +func (mt *EventsTable) doStringFunc(name string) bool { + for _, sf := range mt.stringFuncs { + if sf.title != name { + continue + } + // log.Info("main: found stringfunc name:", name) + r := new(guipb.StringRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + r.Vals = append(r.Vals, sf.f(m)) + // log.Info("main: adding", name, r.Vals) + } + mt.pb.StringRows = append(mt.pb.StringRows, r) + return true + } + return false +} + +func (mt *EventsTable) doButtonFunc(name string) bool { + for _, sf := range mt.buttonFuncs { + if sf.title != name { + continue + } + // log.Info("main: found stringfunc name:", name) + r := new(guipb.ButtonRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + r.Vals = append(r.Vals, sf.f(m)) + // log.Info("main: adding", name, r.Vals) + } + mt.pb.ButtonRows = append(mt.pb.ButtonRows, r) + return true + } + return false +} + +func (mt *EventsTable) doIntFunc(name string) bool { + for _, sf := range mt.intFuncs { + if sf.title != name { + continue + } + // log.Info("main: found intfunc name:", name) + r := new(guipb.IntRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + r.Vals = append(r.Vals, int64(sf.f(m))) + // log.Info("main: adding", name, r.Vals) + } + mt.pb.IntRows = append(mt.pb.IntRows, r) + return true + } + return false +} + +func (mt *EventsTable) doTimeFunc(name string) bool { + for _, sf := range mt.timeFuncs { + if sf.title != name { + continue + } + // log.Info("main: found timefunc name:", name) + r := new(guipb.TimeRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + t := sf.f(m) + r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time + // log.Info("main: adding", name, r.Vals) + } + mt.pb.TimeRows = append(mt.pb.TimeRows, r) + return true + } + return false +} + +func (mt *EventsTable) MakeTable() { + for _, name := range mt.pb.Order { + // log.Info("main: looking for row name()", name) + if mt.doStringFunc(name) { + continue + } + if mt.doIntFunc(name) { + continue + } + if mt.doTimeFunc(name) { + continue + } + if mt.doButtonFunc(name) { + continue + } + } +} + +func (t *EventsTable) AddHostname() *EventStringFunc { + sf := t.AddStringFunc("Hostname", func(m *Event) string { + return m.Hostname + }) + return sf +} + +func (t *EventsTable) AddLocalPort() { + t.AddIntFunc("LocalPort", func(m *Event) int { + return int(m.LocalPort) + }) +} +func (mt *EventsTable) NewUuid() { + mt.pb.Uuid = uuid.New().String() +} + +// START TABLE UPDATE +func (mt *EventsTable) todoUpdate() { + for _, name := range mt.pb.Order { + // log.Info("Eventpb: trying to update row()", name) + if mt.updateStringFunc(name) { + continue + } + if mt.updateTimeFunc(name) { + continue + } + /* + if mt.updateIntFunc(name) { + continue + } + */ + } + // mt.dumpStringFunc("Hostname") + mt.parent.UpdateTable(mt.pb) +} + +func (mt *EventsTable) dumpStringFunc(name string) { + for i, r := range mt.pb.StringRows { + // log.Info("could use", i, r.Header.Name, "for name =", name) + if r.Header.Name == name { + log.Info("dump Strings row", i, r.Header.Name, r.Vals) + break + } + } +} + +func (mt *EventsTable) updateStringFunc(name string) bool { + // log.Info("LOOKING FOR STRING row", name) + var found *guipb.StringRow + for _, r := range mt.pb.StringRows { + // log.Info("could use", i, r.Header.Name, "for name =", name) + if r.Header.Name == name { + // log.Info("found row", i, r.Header.Name) + found = r + break + } + } + if found == nil { + log.Info("did not find string row", name) + return false + } + for _, sf := range mt.stringFuncs { + if sf.title != name { + continue + } + // log.Info("Eventpb: starting", name, found.Vals) + for i, _ := range found.Vals { + tmp := sf.f(mt.x.Events[i]) + if tmp == "www.wit.com" { + log.Info("virtpb: FOUND WWW", i) + tmp = "new.www" + } + found.Vals[i] = tmp + } + // log.Info("Eventpb: ending", name, found.Vals) + return true + } + return false +} + +func (mt *EventsTable) updateTimeFunc(name string) bool { + log.Info("LOOKING FOR TIME row", name) + var found *guipb.TimeRow + for i, r := range mt.pb.TimeRows { + // log.Info("could use", i, r.Header.Name, "for name =", name) + if r.Header.Name == name { + log.Info("found row", i, r.Header.Name) + found = r + break + } + } + if found == nil { + log.Info("did not find time row", name) + return false + } + for _, sf := range mt.timeFuncs { + if sf.title != name { + continue + } + // log.Info("updateTimeFunc() has row len =", len(mt.x.Events)) + // log.Info("virtpb: starting", name, found.Vals) + for i, _ := range found.Vals { + newt := sf.f(mt.x.Events[i]) + found.Vals[i] = timestamppb.New(newt) // convert to protobuf time + } + // log.Info("virtpb: ending", name, found.Vals) + return true + } + return false +} + +func (mt *EventsTable) Delete() { + if mt == nil { + log.Info("mt == nil table already deleted") + return + } + // log.Info("table Delete here") + mt.parent.DeleteTable(mt.pb) +} + +func (mt *EventsTable) eventsCustom(w *guipb.Widget) { + row := mt.x.Events[w.Location.Y-1] + // log.Info("got to eventsCustom() with", w.Location.X, w.Location.Y-1) + + for _, sf := range mt.buttonFuncs { + if sf.order == int(w.Location.X) { + // log.Info("found order", sf.order) + if sf.Custom != nil { + log.Info("doing Custom() func for button") + sf.Custom(row) + return + } + } + } + mt.CustomFunc(row) +} + +func (mt *EventsTable) Custom(f func(*Event)) { + mt.pb.RegisterCustom(mt.eventsCustom) + mt.CustomFunc = f +} + +func (mt *EventsTable) GetUuid() string { + return mt.pb.Uuid +} + +// END TABLE UPDATE + +// END GUI diff --git a/event.marshal.pb.go b/event.marshal.pb.go new file mode 100644 index 0000000..07a4024 --- /dev/null +++ b/event.marshal.pb.go @@ -0,0 +1,56 @@ +// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. +// This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC +// go install go.wit.com/apps/autogenpb@latest +// +// define which structs (messages) you want to use in the .proto file +// Then sort.pb.go and marshal.pb.go files are autogenerated +// +// autogenpb uses it and has an example .proto file with instructions +// + +package main + +import ( + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/encoding/prototext" + "google.golang.org/protobuf/proto" +) + +// human readable JSON +func (v *Events) FormatJSON() string { + return protojson.Format(v) +} + +// marshal json +func (v *Events) MarshalJSON() ([]byte, error) { + return protojson.Marshal(v) +} + +// unmarshal json +func (v *Events) UnmarshalJSON(data []byte) error { + return protojson.Unmarshal(data, v) +} + +// apparently this isn't stable, but it's awesomely better +// https://protobuf.dev/reference/go/faq/#unstable-text +// it's brilliant for config files! +func (v *Events) FormatTEXT() string { + v.fixUuid() + return prototext.Format(v) +} + +// unmarshalTEXT. This reads the .text config file back in after the user edits it +func (v *Events) UnmarshalTEXT(data []byte) error { + return prototext.Unmarshal(data, v) +} + +// marshal to wire. This is called winning. +func (v *Events) Marshal() ([]byte, error) { + v.fixUuid() + return proto.Marshal(v) +} + +// unmarshal from wire. You have won. +func (v *Events) Unmarshal(data []byte) error { + return proto.Unmarshal(data, v) +} diff --git a/event.pb.go b/event.pb.go new file mode 100644 index 0000000..19100c2 --- /dev/null +++ b/event.pb.go @@ -0,0 +1,470 @@ +// Code modified by go.wit.com/apps/autogenpb DO NOT EDIT. +// +// user defined Mutex locks were auto added +// +// autogenpb version & build time: v0.0.65 2025-03-12_15:38:32_UTC +// autogenpb auto generates Sort(), Unique() and Marshal() functions +// go install go.wit.com/apps/autogenpb@latest + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc v3.21.12 +// source: event.proto + +package main // autogenpb changed the package name + +import ( + reflect "reflect" + sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GusEventType int32 + +const ( + GusEventType_Connect GusEventType = 0 // a socket connect attempt + GusEventType_Disconnect GusEventType = 1 // a socket closed + GusEventType_Enable GusEventType = 2 // listening on a port was enabled + GusEventType_Disable GusEventType = 3 // listening on a port was disabled +) + +// Enum value maps for GusEventType. +var ( + GusEventType_name = map[int32]string{ + 0: "Connect", + 1: "Disconnect", + 2: "Enable", + 3: "Disable", + } + GusEventType_value = map[string]int32{ + "Connect": 0, + "Disconnect": 1, + "Enable": 2, + "Disable": 3, + } +) + +func (x GusEventType) Enum() *GusEventType { + p := new(GusEventType) + *p = x + return p +} + +func (x GusEventType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (GusEventType) Descriptor() protoreflect.EnumDescriptor { + return file_event_proto_enumTypes[0].Descriptor() +} + +func (GusEventType) Type() protoreflect.EnumType { + return &file_event_proto_enumTypes[0] +} + +func (x GusEventType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use GusEventType.Descriptor instead. +func (GusEventType) EnumDescriptor() ([]byte, []int) { + return file_event_proto_rawDescGZIP(), []int{0} +} + +type GusSocket struct { + sync.RWMutex // auto-added by go.wit.com/apps/autogenpb + + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + SrcHostname string `protobuf:"bytes,1,opt,name=srcHostname,proto3" json:"srcHostname,omitempty"` // the hostname + SrcIp string `protobuf:"bytes,2,opt,name=srcIp,proto3" json:"srcIp,omitempty"` // the IPv4 or IPv6 address + SrcPort string `protobuf:"bytes,3,opt,name=srcPort,proto3" json:"srcPort,omitempty"` // the port + DestHostname string `protobuf:"bytes,4,opt,name=destHostname,proto3" json:"destHostname,omitempty"` // the hostname + DestIp string `protobuf:"bytes,5,opt,name=destIp,proto3" json:"destIp,omitempty"` // the IPv4 or IPv6 address + DestPort string `protobuf:"bytes,6,opt,name=destPort,proto3" json:"destPort,omitempty"` // the port +} + +func (x *GusSocket) Reset() { + *x = GusSocket{} + if protoimpl.UnsafeEnabled { + mi := &file_event_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GusSocket) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GusSocket) ProtoMessage() {} + +func (x *GusSocket) ProtoReflect() protoreflect.Message { + mi := &file_event_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GusSocket.ProtoReflect.Descriptor instead. +func (*GusSocket) Descriptor() ([]byte, []int) { + return file_event_proto_rawDescGZIP(), []int{0} +} + +func (x *GusSocket) GetSrcHostname() string { + if x != nil { + return x.SrcHostname + } + return "" +} + +func (x *GusSocket) GetSrcIp() string { + if x != nil { + return x.SrcIp + } + return "" +} + +func (x *GusSocket) GetSrcPort() string { + if x != nil { + return x.SrcPort + } + return "" +} + +func (x *GusSocket) GetDestHostname() string { + if x != nil { + return x.DestHostname + } + return "" +} + +func (x *GusSocket) GetDestIp() string { + if x != nil { + return x.DestIp + } + return "" +} + +func (x *GusSocket) GetDestPort() string { + if x != nil { + return x.DestPort + } + return "" +} + +type Event struct { + sync.RWMutex // auto-added by go.wit.com/apps/autogenpb + + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hostname string `protobuf:"bytes,1,opt,name=Hostname,proto3" json:"Hostname,omitempty"` // the hostname + LocalPort int64 `protobuf:"varint,2,opt,name=localPort,proto3" json:"localPort,omitempty"` // the port gus was listening on + Etype GusEventType `protobuf:"varint,3,opt,name=etype,proto3,enum=gus.GusEventType" json:"etype,omitempty"` // what kind of event was this + Sock *GusSocket `protobuf:"bytes,4,opt,name=sock,proto3" json:"sock,omitempty"` // socket details if event needs them + Ctime *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=ctime,proto3" json:"ctime,omitempty"` // event create time + Etime *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=etime,proto3" json:"etime,omitempty"` // event end time +} + +func (x *Event) Reset() { + *x = Event{} + if protoimpl.UnsafeEnabled { + mi := &file_event_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Event) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Event) ProtoMessage() {} + +func (x *Event) ProtoReflect() protoreflect.Message { + mi := &file_event_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Event.ProtoReflect.Descriptor instead. +func (*Event) Descriptor() ([]byte, []int) { + return file_event_proto_rawDescGZIP(), []int{1} +} + +func (x *Event) GetHostname() string { + if x != nil { + return x.Hostname + } + return "" +} + +func (x *Event) GetLocalPort() int64 { + if x != nil { + return x.LocalPort + } + return 0 +} + +func (x *Event) GetEtype() GusEventType { + if x != nil { + return x.Etype + } + return GusEventType_Connect +} + +func (x *Event) GetSock() *GusSocket { + if x != nil { + return x.Sock + } + return nil +} + +func (x *Event) GetCtime() *timestamppb.Timestamp { + if x != nil { + return x.Ctime + } + return nil +} + +func (x *Event) GetEtime() *timestamppb.Timestamp { + if x != nil { + return x.Etime + } + return nil +} + +type Events struct { + // sync.RWMutex // skipped. protobuf file has `autogenpb:nomutex` + + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // `autogenpb:uuid:4e91f9e6-f545-4c72-bec4-ab951276da1d` + Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // `autogenpb:version:v0.0.1` + Events []*Event `protobuf:"bytes,3,rep,name=events,proto3" json:"events,omitempty"` +} + +func (x *Events) Reset() { + *x = Events{} + if protoimpl.UnsafeEnabled { + mi := &file_event_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Events) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Events) ProtoMessage() {} + +func (x *Events) ProtoReflect() protoreflect.Message { + mi := &file_event_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Events.ProtoReflect.Descriptor instead. +func (*Events) Descriptor() ([]byte, []int) { + return file_event_proto_rawDescGZIP(), []int{2} +} + +func (x *Events) GetUuid() string { + if x != nil { + return x.Uuid + } + return "" +} + +func (x *Events) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *Events) GetEvents() []*Event { + if x != nil { + return x.Events + } + return nil +} + +var File_event_proto protoreflect.FileDescriptor + +var file_event_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x67, + 0x75, 0x73, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0xb5, 0x01, 0x0a, 0x09, 0x47, 0x75, 0x73, 0x53, 0x6f, 0x63, 0x6b, 0x65, + 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x72, 0x63, 0x48, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x72, 0x63, 0x48, 0x6f, 0x73, 0x74, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x72, 0x63, 0x49, 0x70, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x73, 0x72, 0x63, 0x49, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x72, 0x63, + 0x50, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x72, 0x63, 0x50, + 0x6f, 0x72, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x64, 0x65, 0x73, 0x74, 0x48, 0x6f, 0x73, 0x74, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x65, 0x73, 0x74, 0x48, + 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x73, 0x74, 0x49, + 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x65, 0x73, 0x74, 0x49, 0x70, 0x12, + 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x73, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x64, 0x65, 0x73, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x22, 0xf2, 0x01, 0x0a, 0x05, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x48, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x48, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x50, 0x6f, 0x72, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x50, 0x6f, 0x72, 0x74, 0x12, + 0x27, 0x0a, 0x05, 0x65, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x11, + 0x2e, 0x67, 0x75, 0x73, 0x2e, 0x47, 0x75, 0x73, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, + 0x65, 0x52, 0x05, 0x65, 0x74, 0x79, 0x70, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x73, 0x6f, 0x63, 0x6b, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x67, 0x75, 0x73, 0x2e, 0x47, 0x75, 0x73, + 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x52, 0x04, 0x73, 0x6f, 0x63, 0x6b, 0x12, 0x30, 0x0a, 0x05, + 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x30, + 0x0a, 0x05, 0x65, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x05, 0x65, 0x74, 0x69, 0x6d, 0x65, + 0x22, 0x5a, 0x0a, 0x06, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, + 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, + 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x67, 0x75, 0x73, 0x2e, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2a, 0x44, 0x0a, 0x0c, + 0x47, 0x75, 0x73, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, + 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x10, 0x00, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x69, 0x73, + 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x6e, 0x61, + 0x62, 0x6c, 0x65, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, + 0x10, 0x03, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_event_proto_rawDescOnce sync.Once + file_event_proto_rawDescData = file_event_proto_rawDesc +) + +func file_event_proto_rawDescGZIP() []byte { + file_event_proto_rawDescOnce.Do(func() { + file_event_proto_rawDescData = protoimpl.X.CompressGZIP(file_event_proto_rawDescData) + }) + return file_event_proto_rawDescData +} + +var file_event_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_event_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_event_proto_goTypes = []interface{}{ + (GusEventType)(0), // 0: gus.GusEventType + (*GusSocket)(nil), // 1: gus.GusSocket + (*Event)(nil), // 2: gus.Event + (*Events)(nil), // 3: gus.Events + (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp +} +var file_event_proto_depIdxs = []int32{ + 0, // 0: gus.Event.etype:type_name -> gus.GusEventType + 1, // 1: gus.Event.sock:type_name -> gus.GusSocket + 4, // 2: gus.Event.ctime:type_name -> google.protobuf.Timestamp + 4, // 3: gus.Event.etime:type_name -> google.protobuf.Timestamp + 2, // 4: gus.Events.events:type_name -> gus.Event + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_event_proto_init() } +func file_event_proto_init() { + if File_event_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_event_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GusSocket); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_event_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Event); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_event_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Events); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_event_proto_rawDesc, + NumEnums: 1, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_event_proto_goTypes, + DependencyIndexes: file_event_proto_depIdxs, + EnumInfos: file_event_proto_enumTypes, + MessageInfos: file_event_proto_msgTypes, + }.Build() + File_event_proto = out.File + file_event_proto_rawDesc = nil + file_event_proto_goTypes = nil + file_event_proto_depIdxs = nil +} diff --git a/event.sort.pb.go b/event.sort.pb.go new file mode 100644 index 0000000..f1b383a --- /dev/null +++ b/event.sort.pb.go @@ -0,0 +1,200 @@ +// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. +// This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC +// go install go.wit.com/apps/autogenpb@latest +// +// define which structs (messages) you want to use in the .proto file +// Then sort.pb.go and marshal.pb.go files are autogenerated +// +// autogenpb uses it and has an example .proto file with instructions +// + +package main + +import ( + "fmt" + "sync" +) + +// a simple global lock +var eventMu sync.RWMutex + +func (x *Events) fixUuid() { + if x == nil { + return + } + if x.Uuid == "4e91f9e6-f545-4c72-bec4-ab951276da1d" { + return + } + x.Uuid = "4e91f9e6-f545-4c72-bec4-ab951276da1d" + x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" +} + +func NewEvents() *Events { + x := new(Events) + x.Uuid = "4e91f9e6-f545-4c72-bec4-ab951276da1d" + x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" + return x +} + +// START SORT + +// DEFINE THE Events ITERATOR. +// itializes a new iterator. +func newEventsIterator(things []*Events) *EventsIterator { + return &EventsIterator{things: things} +} + +type EventsIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*Events + index int +} + +func (it *EventsIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *EventsIterator) Next() *Events { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in EventsIterator", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE ITERATOR + +// DEFINE THE Event ITERATOR. +// itializes a new iterator. +func newEventIterator(things []*Event) *EventIterator { + return &EventIterator{things: things} +} + +type EventIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*Event + index int +} + +func (it *EventIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *EventIterator) Next() *Event { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in EventIterator", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE ITERATOR + +// DEFINE THE GusSocket ITERATOR. +// itializes a new iterator. +func newGusSocketIterator(things []*GusSocket) *GusSocketIterator { + return &GusSocketIterator{things: things} +} + +type GusSocketIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*GusSocket + index int +} + +func (it *GusSocketIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *GusSocketIterator) Next() *GusSocket { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in GusSocketIterator", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE ITERATOR + +// safely returns a slice of pointers to the FRUIT protobufs +func (x *Events) allEvents() []*Event { + eventMu.RLock() + defer eventMu.RUnlock() + + // Create a new slice to hold pointers to each FRUIT + var tmp []*Event + tmp = make([]*Event, len(x.Events)) + for i, p := range x.Events { + tmp[i] = p // Copy pointers for safe iteration + } + + return tmp +} + +// safely returns a slice of pointers to the Event protobufs +func (x *Events) selectAllEvents() []*Event { + eventMu.RLock() + defer eventMu.RUnlock() + + // Create a new slice to hold pointers to each Event + var tmp []*Event + tmp = make([]*Event, len(x.Events)) + for i, p := range x.Events { + tmp[i] = p // Copy pointers for safe iteration + } + + return tmp +} + +// END SORT + +func (x *Events) Len() int { + eventMu.RLock() + defer eventMu.RUnlock() + + return len(x.Events) +} + +// just a simple Append() shortcut (but still uses the mutex lock) +func (x *Events) Append(y *Event) { + eventMu.Lock() + defer eventMu.Unlock() + + x.Events = append(x.Events, y) +} + +func (x *Events) All() *EventIterator { + EventPointers := x.selectAllEvents() + + iterator := newEventIterator(EventPointers) + return iterator +} + +func (x *Events) Delete(y *Event) bool { + eventMu.Lock() + defer eventMu.Unlock() + + for i, _ := range x.Events { + if x.Events[i] == y { + x.Events[i] = x.Events[len(x.Events)-1] + x.Events = x.Events[:len(x.Events)-1] + return true + } + } + return false +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4fb028a --- /dev/null +++ b/go.mod @@ -0,0 +1,48 @@ +module go.wit.com/lib/daemons/gus + +go 1.24.1 + +require ( + github.com/gin-gonic/gin v1.10.1 + github.com/google/uuid v1.6.0 + github.com/svent/go-nbreader v0.0.0-20150201200112-7cef48da76dc + go.wit.com/dev/alexflint/arg v1.5.7 + go.wit.com/gui v0.22.47 + go.wit.com/lib/debugger v0.22.31 + go.wit.com/lib/gadgets v0.22.30 + go.wit.com/lib/http/ginpb v0.0.2 + go.wit.com/lib/protobuf/guipb v0.0.12 + go.wit.com/log v0.22.17 + google.golang.org/protobuf v1.36.7 +) + +require ( + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + go.wit.com/dev/alexflint/scalar v1.2.4 // indirect + go.wit.com/lib/gui/logsettings v0.22.30 // indirect + go.wit.com/widget v1.1.30 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..09533d0 --- /dev/null +++ b/go.sum @@ -0,0 +1,92 @@ +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ= +github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/svent/go-nbreader v0.0.0-20150201200112-7cef48da76dc h1:usYkrH2/es/TT7ETdC/qLAagcJPW3EEYFKqvibSnFbA= +github.com/svent/go-nbreader v0.0.0-20150201200112-7cef48da76dc/go.mod h1:pPzZl0vMkUhyoxUF8PAGG5bDRGo7PY80oO/PMmpLkkc= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +go.wit.com/dev/alexflint/arg v1.5.7 h1:qBMiD0cki2RHLm1opnbnIhXH5MXaLroXtdL+NgnSJy0= +go.wit.com/dev/alexflint/arg v1.5.7/go.mod h1:tiXkhaPnYsCq89Lse5Gl4oU8++bejruAFjaSiyMVTRM= +go.wit.com/dev/alexflint/scalar v1.2.4 h1:zmBeEkObwz1lcelwfGNYP2GS6SQ9e0tdv7JdHwMZEEk= +go.wit.com/dev/alexflint/scalar v1.2.4/go.mod h1:kCNO1Fo5LnnK6+qa+zYhP5fdgfC1C+vx1ti99Md+FAM= +go.wit.com/gui v0.22.47 h1:ePBiEsiWHu9O7H/Ptg1ulgZnb9CFwaoiy8kvwN2YWJw= +go.wit.com/gui v0.22.47/go.mod h1:d+Ca9pHTLt6k0IXmiiO9Hl8CCrk98iovTBa7UtbqDjg= +go.wit.com/lib/debugger v0.22.31 h1:/qi9T9xkkLW7+CNF09DFsjrjWYvczUcKvYAPZS7Rxi8= +go.wit.com/lib/debugger v0.22.31/go.mod h1:vHKmErrxScUyxxMkxs2Ep9ytWLcs+vxeNJtEyrNMobQ= +go.wit.com/lib/gadgets v0.22.30 h1:4z6U9dLFPIwfdqfAXJZ+86ecOV/Ex5mTJfghlTnCuVk= +go.wit.com/lib/gadgets v0.22.30/go.mod h1:cJ9z+MbyLgS8l7HW6/khPDXkmzDC44Ap0cXUNymmuD8= +go.wit.com/lib/gui/logsettings v0.22.30 h1:8Y65N0wEMC8/bxBJn3hWfiUblgsGnJrYRhsuK4JXN44= +go.wit.com/lib/gui/logsettings v0.22.30/go.mod h1:b6CLpj5NAlNvarMkGD3WoQMx8aO9xIfx3vYch0uo93E= +go.wit.com/lib/http/ginpb v0.0.2 h1:U4p7ybedIvaTbgALC3hyHj1/950yIInV5R0yq8P6XLc= +go.wit.com/lib/http/ginpb v0.0.2/go.mod h1:G9CIzVBzNFXZRmRVuryH++PHJS+B2KbKSw0gtqp5adU= +go.wit.com/lib/protobuf/guipb v0.0.12 h1:Yxf0eCVRU4R+w33SulLSnkDMi6KiW/mL7O5nHEelVFU= +go.wit.com/lib/protobuf/guipb v0.0.12/go.mod h1:eD5DG8UozJli7Q6BDoIVNThJjcaTfsOi9AGwlk5gOUk= +go.wit.com/log v0.22.17 h1:rAnrUPbQ/k34Fxqq4buKofvwKRvODcV4/qiXJREiqD4= +go.wit.com/log v0.22.17/go.mod h1:XE4lTfAibWgwBJksIk7u3IEJ8xcBvNhnlewYAQGj2Ew= +go.wit.com/widget v1.1.30 h1:O/dIG7QtDrZkR5P6f8JAMyevBiMXSun9vL6F0KFAWV8= +go.wit.com/widget v1.1.30/go.mod h1:wj7TpAr2gk7Poa+v8XQkH1aidnTdgAa/a8GxrMtcztw= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A= +google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= +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.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/portmap.gui.pb.go b/portmap.gui.pb.go new file mode 100644 index 0000000..22259a9 --- /dev/null +++ b/portmap.gui.pb.go @@ -0,0 +1,408 @@ +// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. +// This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC +// go install go.wit.com/apps/autogenpb@latest +// +// define which structs (messages) you want to use in the .proto file +// Then sort.pb.go and marshal.pb.go files are autogenerated +// +// autogenpb uses it and has an example .proto file with instructions +// + +package main + +import ( + "time" + + "github.com/google/uuid" + "go.wit.com/gui" + "go.wit.com/lib/protobuf/guipb" + "go.wit.com/log" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" +) + +// START GUI + +func (x *Portmaps) NewTable(title string) *PortmapsTable { + t := new(PortmapsTable) + t.x = x + pb := new(guipb.Table) + pb.Title = title + t.pb = pb + return t +} + +func (t *PortmapsTable) AddStringFunc(title string, f func(*Portmap) string) *PortmapStringFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(PortmapStringFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.stringFuncs = append(t.stringFuncs, sf) + return sf +} + +func (t *PortmapsTable) AddButtonFunc(title string, f func(*Portmap) string) *PortmapButtonFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(PortmapButtonFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.buttonFuncs = append(t.buttonFuncs, sf) + return sf +} + +func (t *PortmapsTable) AddIntFunc(title string, f func(*Portmap) int) *PortmapIntFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(PortmapIntFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.intFuncs = append(t.intFuncs, sf) + return sf +} + +func (t *PortmapsTable) AddTimeFunc(title string, f func(*Portmap) time.Time) *PortmapTimeFunc { + t.pb.Order = append(t.pb.Order, title) + + sf := new(PortmapTimeFunc) + sf.title = title + sf.f = f + sf.order = t.order + t.order += 1 + t.timeFuncs = append(t.timeFuncs, sf) + return sf +} + +func (sf *PortmapStringFunc) SetTitle(title string) { + sf.title = title +} +func (sf *PortmapIntFunc) SetTitle(title string) { + sf.title = title +} +func (sf *PortmapTimeFunc) SetTitle(title string) { + sf.title = title +} + +func (mt *PortmapsTable) SetParent(p *gui.Node) { + mt.parent = p +} + +func (mt *PortmapsTable) ShowTable() { + // log.Info("ShowTable() SENDING TO GUI") + mt.MakeTable() + mt.parent.ShowTable(mt.pb) +} + +type PortmapStringFunc struct { + title string + f func(*Portmap) string + Custom func(*Portmap) + order int +} + +type PortmapButtonFunc struct { + title string + f func(*Portmap) string + Custom func(*Portmap) + order int +} + +type PortmapIntFunc struct { + title string + f func(*Portmap) int + Custom func(*Portmap) + order int +} + +type PortmapTimeFunc struct { + title string + f func(*Portmap) time.Time + Custom func(*Portmap) + order int +} + +type PortmapsTable struct { + pb *guipb.Table + parent *gui.Node + x *Portmaps + hostnames []string + stringFuncs []*PortmapStringFunc + intFuncs []*PortmapIntFunc + timeFuncs []*PortmapTimeFunc + buttonFuncs []*PortmapButtonFunc + CustomFunc func(*Portmap) + order int +} + +func (mt *PortmapsTable) doStringFunc(name string) bool { + for _, sf := range mt.stringFuncs { + if sf.title != name { + continue + } + // log.Info("main: found stringfunc name:", name) + r := new(guipb.StringRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + r.Vals = append(r.Vals, sf.f(m)) + // log.Info("main: adding", name, r.Vals) + } + mt.pb.StringRows = append(mt.pb.StringRows, r) + return true + } + return false +} + +func (mt *PortmapsTable) doButtonFunc(name string) bool { + for _, sf := range mt.buttonFuncs { + if sf.title != name { + continue + } + // log.Info("main: found stringfunc name:", name) + r := new(guipb.ButtonRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + r.Vals = append(r.Vals, sf.f(m)) + // log.Info("main: adding", name, r.Vals) + } + mt.pb.ButtonRows = append(mt.pb.ButtonRows, r) + return true + } + return false +} + +func (mt *PortmapsTable) doIntFunc(name string) bool { + for _, sf := range mt.intFuncs { + if sf.title != name { + continue + } + // log.Info("main: found intfunc name:", name) + r := new(guipb.IntRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + r.Vals = append(r.Vals, int64(sf.f(m))) + // log.Info("main: adding", name, r.Vals) + } + mt.pb.IntRows = append(mt.pb.IntRows, r) + return true + } + return false +} + +func (mt *PortmapsTable) doTimeFunc(name string) bool { + for _, sf := range mt.timeFuncs { + if sf.title != name { + continue + } + // log.Info("main: found timefunc name:", name) + r := new(guipb.TimeRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + t := sf.f(m) + r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time + // log.Info("main: adding", name, r.Vals) + } + mt.pb.TimeRows = append(mt.pb.TimeRows, r) + return true + } + return false +} + +func (mt *PortmapsTable) MakeTable() { + for _, name := range mt.pb.Order { + // log.Info("main: looking for row name()", name) + if mt.doStringFunc(name) { + continue + } + if mt.doIntFunc(name) { + continue + } + if mt.doTimeFunc(name) { + continue + } + if mt.doButtonFunc(name) { + continue + } + } +} + +func (t *PortmapsTable) AddLocalport() { + t.AddIntFunc("Localport", func(m *Portmap) int { + return int(m.Localport) + }) +} + +func (t *PortmapsTable) AddDest() *PortmapStringFunc { + sf := t.AddStringFunc("Dest", func(m *Portmap) string { + return m.Dest + }) + return sf +} + +func (t *PortmapsTable) AddHosts() *PortmapStringFunc { + sf := t.AddStringFunc("Hosts", func(m *Portmap) string { + return m.Hosts + }) + return sf +} + +func (t *PortmapsTable) AddIptables() *PortmapStringFunc { + sf := t.AddStringFunc("Iptables", func(m *Portmap) string { + return m.Iptables + }) + return sf +} +func (mt *PortmapsTable) NewUuid() { + mt.pb.Uuid = uuid.New().String() +} + +// START TABLE UPDATE +func (mt *PortmapsTable) todoUpdate() { + for _, name := range mt.pb.Order { + // log.Info("Portmappb: trying to update row()", name) + if mt.updateStringFunc(name) { + continue + } + if mt.updateTimeFunc(name) { + continue + } + /* + if mt.updateIntFunc(name) { + continue + } + */ + } + // mt.dumpStringFunc("Hostname") + mt.parent.UpdateTable(mt.pb) +} + +func (mt *PortmapsTable) dumpStringFunc(name string) { + for i, r := range mt.pb.StringRows { + // log.Info("could use", i, r.Header.Name, "for name =", name) + if r.Header.Name == name { + log.Info("dump Strings row", i, r.Header.Name, r.Vals) + break + } + } +} + +func (mt *PortmapsTable) updateStringFunc(name string) bool { + // log.Info("LOOKING FOR STRING row", name) + var found *guipb.StringRow + for _, r := range mt.pb.StringRows { + // log.Info("could use", i, r.Header.Name, "for name =", name) + if r.Header.Name == name { + // log.Info("found row", i, r.Header.Name) + found = r + break + } + } + if found == nil { + log.Info("did not find string row", name) + return false + } + for _, sf := range mt.stringFuncs { + if sf.title != name { + continue + } + // log.Info("Portmappb: starting", name, found.Vals) + for i, _ := range found.Vals { + tmp := sf.f(mt.x.Portmaps[i]) + if tmp == "www.wit.com" { + log.Info("virtpb: FOUND WWW", i) + tmp = "new.www" + } + found.Vals[i] = tmp + } + // log.Info("Portmappb: ending", name, found.Vals) + return true + } + return false +} + +func (mt *PortmapsTable) updateTimeFunc(name string) bool { + log.Info("LOOKING FOR TIME row", name) + var found *guipb.TimeRow + for i, r := range mt.pb.TimeRows { + // log.Info("could use", i, r.Header.Name, "for name =", name) + if r.Header.Name == name { + log.Info("found row", i, r.Header.Name) + found = r + break + } + } + if found == nil { + log.Info("did not find time row", name) + return false + } + for _, sf := range mt.timeFuncs { + if sf.title != name { + continue + } + // log.Info("updateTimeFunc() has row len =", len(mt.x.Portmaps)) + // log.Info("virtpb: starting", name, found.Vals) + for i, _ := range found.Vals { + newt := sf.f(mt.x.Portmaps[i]) + found.Vals[i] = timestamppb.New(newt) // convert to protobuf time + } + // log.Info("virtpb: ending", name, found.Vals) + return true + } + return false +} + +func (mt *PortmapsTable) Delete() { + if mt == nil { + log.Info("mt == nil table already deleted") + return + } + // log.Info("table Delete here") + mt.parent.DeleteTable(mt.pb) +} + +func (mt *PortmapsTable) portmapsCustom(w *guipb.Widget) { + row := mt.x.Portmaps[w.Location.Y-1] + // log.Info("got to portmapsCustom() with", w.Location.X, w.Location.Y-1) + + for _, sf := range mt.buttonFuncs { + if sf.order == int(w.Location.X) { + // log.Info("found order", sf.order) + if sf.Custom != nil { + log.Info("doing Custom() func for button") + sf.Custom(row) + return + } + } + } + mt.CustomFunc(row) +} + +func (mt *PortmapsTable) Custom(f func(*Portmap)) { + mt.pb.RegisterCustom(mt.portmapsCustom) + mt.CustomFunc = f +} + +func (mt *PortmapsTable) GetUuid() string { + return mt.pb.Uuid +} + +// END TABLE UPDATE + +// END GUI diff --git a/portmap.marshal.pb.go b/portmap.marshal.pb.go new file mode 100644 index 0000000..35cd8a8 --- /dev/null +++ b/portmap.marshal.pb.go @@ -0,0 +1,56 @@ +// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. +// This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC +// go install go.wit.com/apps/autogenpb@latest +// +// define which structs (messages) you want to use in the .proto file +// Then sort.pb.go and marshal.pb.go files are autogenerated +// +// autogenpb uses it and has an example .proto file with instructions +// + +package main + +import ( + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/encoding/prototext" + "google.golang.org/protobuf/proto" +) + +// human readable JSON +func (v *Portmaps) FormatJSON() string { + return protojson.Format(v) +} + +// marshal json +func (v *Portmaps) MarshalJSON() ([]byte, error) { + return protojson.Marshal(v) +} + +// unmarshal json +func (v *Portmaps) UnmarshalJSON(data []byte) error { + return protojson.Unmarshal(data, v) +} + +// apparently this isn't stable, but it's awesomely better +// https://protobuf.dev/reference/go/faq/#unstable-text +// it's brilliant for config files! +func (v *Portmaps) FormatTEXT() string { + v.fixUuid() + return prototext.Format(v) +} + +// unmarshalTEXT. This reads the .text config file back in after the user edits it +func (v *Portmaps) UnmarshalTEXT(data []byte) error { + return prototext.Unmarshal(data, v) +} + +// marshal to wire. This is called winning. +func (v *Portmaps) Marshal() ([]byte, error) { + v.fixUuid() + return proto.Marshal(v) +} + +// unmarshal from wire. You have won. +func (v *Portmaps) Unmarshal(data []byte) error { + return proto.Unmarshal(data, v) +} diff --git a/portmap.pb.go b/portmap.pb.go new file mode 100644 index 0000000..82cd7ab --- /dev/null +++ b/portmap.pb.go @@ -0,0 +1,294 @@ +// Code modified by go.wit.com/apps/autogenpb DO NOT EDIT. +// +// user defined Mutex locks were auto added +// +// autogenpb version & build time: v0.0.65 2025-03-12_15:38:32_UTC +// autogenpb auto generates Sort(), Unique() and Marshal() functions +// go install go.wit.com/apps/autogenpb@latest + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc v3.21.12 +// source: portmap.proto + +package main // autogenpb changed the package name + +import ( + reflect "reflect" + sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Portmap struct { + sync.RWMutex // auto-added by go.wit.com/apps/autogenpb + + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Localport int64 `protobuf:"varint,1,opt,name=localport,proto3" json:"localport,omitempty"` // `autogenpb:unique` + Dest string `protobuf:"bytes,2,opt,name=dest,proto3" json:"dest,omitempty"` + Enabled bool `protobuf:"varint,3,opt,name=enabled,proto3" json:"enabled,omitempty"` + AllowIPv4 bool `protobuf:"varint,4,opt,name=allowIPv4,proto3" json:"allowIPv4,omitempty"` + UseME bool `protobuf:"varint,5,opt,name=useME,proto3" json:"useME,omitempty"` + Hosts string `protobuf:"bytes,6,opt,name=hosts,proto3" json:"hosts,omitempty"` + Iptables string `protobuf:"bytes,7,opt,name=iptables,proto3" json:"iptables,omitempty"` +} + +func (x *Portmap) Reset() { + *x = Portmap{} + if protoimpl.UnsafeEnabled { + mi := &file_portmap_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Portmap) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Portmap) ProtoMessage() {} + +func (x *Portmap) ProtoReflect() protoreflect.Message { + mi := &file_portmap_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Portmap.ProtoReflect.Descriptor instead. +func (*Portmap) Descriptor() ([]byte, []int) { + return file_portmap_proto_rawDescGZIP(), []int{0} +} + +func (x *Portmap) GetLocalport() int64 { + if x != nil { + return x.Localport + } + return 0 +} + +func (x *Portmap) GetDest() string { + if x != nil { + return x.Dest + } + return "" +} + +func (x *Portmap) GetEnabled() bool { + if x != nil { + return x.Enabled + } + return false +} + +func (x *Portmap) GetAllowIPv4() bool { + if x != nil { + return x.AllowIPv4 + } + return false +} + +func (x *Portmap) GetUseME() bool { + if x != nil { + return x.UseME + } + return false +} + +func (x *Portmap) GetHosts() string { + if x != nil { + return x.Hosts + } + return "" +} + +func (x *Portmap) GetIptables() string { + if x != nil { + return x.Iptables + } + return "" +} + +type Portmaps struct { + // sync.RWMutex // skipped. protobuf file has `autogenpb:nomutex` + + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // `autogenpb:uuid:49a865ea-292d-48fd-8dc2-d0f82d5fd016` + Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // `autogenpb:version:v0.0.1` + Portmaps []*Portmap `protobuf:"bytes,3,rep,name=portmaps,proto3" json:"portmaps,omitempty"` +} + +func (x *Portmaps) Reset() { + *x = Portmaps{} + if protoimpl.UnsafeEnabled { + mi := &file_portmap_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Portmaps) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Portmaps) ProtoMessage() {} + +func (x *Portmaps) ProtoReflect() protoreflect.Message { + mi := &file_portmap_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Portmaps.ProtoReflect.Descriptor instead. +func (*Portmaps) Descriptor() ([]byte, []int) { + return file_portmap_proto_rawDescGZIP(), []int{1} +} + +func (x *Portmaps) GetUuid() string { + if x != nil { + return x.Uuid + } + return "" +} + +func (x *Portmaps) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *Portmaps) GetPortmaps() []*Portmap { + if x != nil { + return x.Portmaps + } + return nil +} + +var File_portmap_proto protoreflect.FileDescriptor + +var file_portmap_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x70, 0x6f, 0x72, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x03, 0x67, 0x75, 0x73, 0x22, 0xbb, 0x01, 0x0a, 0x07, 0x50, 0x6f, 0x72, 0x74, 0x6d, 0x61, 0x70, + 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x12, + 0x0a, 0x04, 0x64, 0x65, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x07, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x49, 0x50, 0x76, 0x34, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x09, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x49, 0x50, 0x76, 0x34, 0x12, 0x14, 0x0a, 0x05, 0x75, 0x73, + 0x65, 0x4d, 0x45, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x75, 0x73, 0x65, 0x4d, 0x45, + 0x12, 0x14, 0x0a, 0x05, 0x68, 0x6f, 0x73, 0x74, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x68, 0x6f, 0x73, 0x74, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x70, 0x74, 0x61, 0x62, 0x6c, + 0x65, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x69, 0x70, 0x74, 0x61, 0x62, 0x6c, + 0x65, 0x73, 0x22, 0x62, 0x0a, 0x08, 0x50, 0x6f, 0x72, 0x74, 0x6d, 0x61, 0x70, 0x73, 0x12, 0x12, + 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, + 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x28, 0x0a, 0x08, + 0x70, 0x6f, 0x72, 0x74, 0x6d, 0x61, 0x70, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, + 0x2e, 0x67, 0x75, 0x73, 0x2e, 0x50, 0x6f, 0x72, 0x74, 0x6d, 0x61, 0x70, 0x52, 0x08, 0x70, 0x6f, + 0x72, 0x74, 0x6d, 0x61, 0x70, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_portmap_proto_rawDescOnce sync.Once + file_portmap_proto_rawDescData = file_portmap_proto_rawDesc +) + +func file_portmap_proto_rawDescGZIP() []byte { + file_portmap_proto_rawDescOnce.Do(func() { + file_portmap_proto_rawDescData = protoimpl.X.CompressGZIP(file_portmap_proto_rawDescData) + }) + return file_portmap_proto_rawDescData +} + +var file_portmap_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_portmap_proto_goTypes = []interface{}{ + (*Portmap)(nil), // 0: gus.Portmap + (*Portmaps)(nil), // 1: gus.Portmaps +} +var file_portmap_proto_depIdxs = []int32{ + 0, // 0: gus.Portmaps.portmaps:type_name -> gus.Portmap + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_portmap_proto_init() } +func file_portmap_proto_init() { + if File_portmap_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_portmap_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Portmap); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_portmap_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Portmaps); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_portmap_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_portmap_proto_goTypes, + DependencyIndexes: file_portmap_proto_depIdxs, + MessageInfos: file_portmap_proto_msgTypes, + }.Build() + File_portmap_proto = out.File + file_portmap_proto_rawDesc = nil + file_portmap_proto_goTypes = nil + file_portmap_proto_depIdxs = nil +} diff --git a/portmap.sort.pb.go b/portmap.sort.pb.go new file mode 100644 index 0000000..cfe6eff --- /dev/null +++ b/portmap.sort.pb.go @@ -0,0 +1,203 @@ +// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. +// This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC +// go install go.wit.com/apps/autogenpb@latest +// +// define which structs (messages) you want to use in the .proto file +// Then sort.pb.go and marshal.pb.go files are autogenerated +// +// autogenpb uses it and has an example .proto file with instructions +// + +package main + +import ( + "fmt" + "sync" +) + +// a simple global lock +var portmapMu sync.RWMutex + +func (x *Portmaps) fixUuid() { + if x == nil { + return + } + if x.Uuid == "49a865ea-292d-48fd-8dc2-d0f82d5fd016" { + return + } + x.Uuid = "49a865ea-292d-48fd-8dc2-d0f82d5fd016" + x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" +} + +func NewPortmaps() *Portmaps { + x := new(Portmaps) + x.Uuid = "49a865ea-292d-48fd-8dc2-d0f82d5fd016" + x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" + return x +} + +// START SORT + +// DEFINE THE Portmaps ITERATOR. +// itializes a new iterator. +func newPortmapsIterator(things []*Portmaps) *PortmapsIterator { + return &PortmapsIterator{things: things} +} + +type PortmapsIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*Portmaps + index int +} + +func (it *PortmapsIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *PortmapsIterator) Next() *Portmaps { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in PortmapsIterator", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE ITERATOR + +// DEFINE THE Portmap ITERATOR. +// itializes a new iterator. +func newPortmapIterator(things []*Portmap) *PortmapIterator { + return &PortmapIterator{things: things} +} + +type PortmapIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*Portmap + index int +} + +func (it *PortmapIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *PortmapIterator) Next() *Portmap { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in PortmapIterator", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE ITERATOR + +// safely returns a slice of pointers to the FRUIT protobufs +func (x *Portmaps) allPortmaps() []*Portmap { + portmapMu.RLock() + defer portmapMu.RUnlock() + + // Create a new slice to hold pointers to each FRUIT + var tmp []*Portmap + tmp = make([]*Portmap, len(x.Portmaps)) + for i, p := range x.Portmaps { + tmp[i] = p // Copy pointers for safe iteration + } + + return tmp +} + +// safely returns a slice of pointers to the Portmap protobufs +func (x *Portmaps) selectAllPortmaps() []*Portmap { + portmapMu.RLock() + defer portmapMu.RUnlock() + + // Create a new slice to hold pointers to each Portmap + var tmp []*Portmap + tmp = make([]*Portmap, len(x.Portmaps)) + for i, p := range x.Portmaps { + tmp[i] = p // Copy pointers for safe iteration + } + + return tmp +} + +// END SORT + +func (x *Portmaps) Len() int { + portmapMu.RLock() + defer portmapMu.RUnlock() + + return len(x.Portmaps) +} + +// just a simple Append() shortcut (but still uses the mutex lock) +func (x *Portmaps) Append(y *Portmap) { + portmapMu.Lock() + defer portmapMu.Unlock() + + x.Portmaps = append(x.Portmaps, y) +} + +func (x *Portmaps) All() *PortmapIterator { + PortmapPointers := x.selectAllPortmaps() + + iterator := newPortmapIterator(PortmapPointers) + return iterator +} + +func (x *Portmaps) Delete(y *Portmap) bool { + portmapMu.Lock() + defer portmapMu.Unlock() + + for i, _ := range x.Portmaps { + if x.Portmaps[i] == y { + x.Portmaps[i] = x.Portmaps[len(x.Portmaps)-1] + x.Portmaps = x.Portmaps[:len(x.Portmaps)-1] + return true + } + } + return false +} + +// lookup a Portmaps by the Localport +func (x *Portmaps) FindByLocalport(y int64) *Portmap { + if x == nil { + return nil + } + + portmapMu.RLock() + defer portmapMu.RUnlock() + + for i, _ := range x.Portmaps { + if x.Portmaps[i].Localport == y { + return x.Portmaps[i] + } + } + return nil +} + +// returns a Portmap if Localport matches, otherwise create +func (x *Portmaps) InsertByLocalport(y int64) *Portmap { + portmapMu.Lock() + defer portmapMu.Unlock() + + for _, z := range x.Portmaps { + if z.Localport == y { + return z + } + } + + z := new(Portmap) + z.Localport = y + x.Portmaps = append(x.Portmaps, z) + return z +}