From bd0b192fa0605c7167dcfe296cc17cde3ab517da Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Fri, 21 Jul 2023 15:18:28 -0400
Subject: [PATCH 1/2] feat: add 'noop' transport
Add a noop transport option. Setting the config flag 'protocol' to
"none" or "" will configure yggd with a no-op transport. All the rest of
the dispatch and routing flows are unaffected, but no data is
transported to or from the client.
Signed-off-by: Link Dupont
---
cmd/yggd/main.go | 12 +++++++++++-
internal/transport/noop.go | 33 +++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 internal/transport/noop.go
diff --git a/cmd/yggd/main.go b/cmd/yggd/main.go
index 2bc096ef..80c70622 100644
--- a/cmd/yggd/main.go
+++ b/cmd/yggd/main.go
@@ -140,6 +140,16 @@ func setupClient(
if err != nil {
return nil, nil, cli.Exit(fmt.Errorf("cannot create HTTP transport: %w", err), 1)
}
+ case "none":
+ var err error
+ transporter, err = transport.NewNoopTransport()
+ if err != nil {
+ return nil, nil, cli.Exit(fmt.Errorf("cannot create no-op transport: %w", err), 1)
+ }
+ log.Info("no network protocol specified - no data will be sent or received over the network")
+ for _, server := range config.DefaultConfig.Server {
+ log.Warnf("no network protocol specified - ignoring server option '%v'", server)
+ }
default:
return nil, nil, cli.Exit(
fmt.Errorf("unsupported transport protocol: %v", config.DefaultConfig.Protocol),
@@ -436,7 +446,7 @@ func main() {
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: config.FlagNameProtocol,
- Usage: "Transmit data remotely using `PROTOCOL` ('mqtt' or 'http')",
+ Usage: "Transmit data remotely using `PROTOCOL` ('mqtt', 'http' or 'none')",
Value: "mqtt",
}),
altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
diff --git a/internal/transport/noop.go b/internal/transport/noop.go
new file mode 100644
index 00000000..bf142622
--- /dev/null
+++ b/internal/transport/noop.go
@@ -0,0 +1,33 @@
+package transport
+
+import "crypto/tls"
+
+// Noop is a Transporter that does nothing. This Transport is used to enable a
+// "local only" dispatch mode.
+type Noop struct{}
+
+func NewNoopTransport() (*Noop, error) {
+ return &Noop{}, nil
+}
+
+func (t *Noop) Connect() error {
+ return nil
+}
+
+func (t *Noop) Disconnect(quiesce uint) {}
+
+func (t *Noop) Tx(addr string, metadata map[string]string, data []byte) (responseCode int, responseMetadata map[string]string, responseData []byte, err error) {
+ return
+}
+
+func (t *Noop) SetRxHandler(f RxHandlerFunc) error {
+ return nil
+}
+
+func (t *Noop) ReloadTLSConfig(tlsConfig *tls.Config) error {
+ return nil
+}
+
+func (t *Noop) SetEventHandler(f EventHandlerFunc) error {
+ return nil
+}
From 92c30e91fec7cd21ce7d8527df08c566499ee720 Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Tue, 15 Aug 2023 12:52:41 -0400
Subject: [PATCH 2/2] ci(srpm): Remove %changelog section from spec
---
dist/srpm/yggdrasil.spec.in | 3 ---
1 file changed, 3 deletions(-)
diff --git a/dist/srpm/yggdrasil.spec.in b/dist/srpm/yggdrasil.spec.in
index f046b669..e89cb98d 100644
--- a/dist/srpm/yggdrasil.spec.in
+++ b/dist/srpm/yggdrasil.spec.in
@@ -102,6 +102,3 @@ export %gomodulesmode
%{_mandir}/man1/*
%gopkgfiles
-
-%changelog
-%autochangelog