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

Add 'noop' transport #145

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion cmd/yggd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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')",
subpop marked this conversation as resolved.
Show resolved Hide resolved
Value: "mqtt",
}),
altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
Expand Down
3 changes: 0 additions & 3 deletions dist/srpm/yggdrasil.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,3 @@ export %gomodulesmode
%{_mandir}/man1/*

%gopkgfiles

%changelog
%autochangelog
33 changes: 33 additions & 0 deletions internal/transport/noop.go
Original file line number Diff line number Diff line change
@@ -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) {
subpop marked this conversation as resolved.
Show resolved Hide resolved
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
}