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

Complete refactor #116

Merged
merged 7 commits into from
Dec 6, 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
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Build
run: go build -v .

- name: Test
run: go test ./...

build_docker:
name: Docker
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ linters-settings:
check-shadowing: false
misspell:
locale: US
nlreturn:
# Size of the block (including return statement that is still "OK")
# so no return split required.
# Default: 1
block-size: 3
staticcheck:
checks: ["all"]
stylecheck:
Expand Down
2 changes: 1 addition & 1 deletion components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
Name = "inx-mqtt"

// Version of the app.
Version = "2.0.0-alpha.3"
Version = "2.0.0-alpha.4"
)

func App() *app.App {
Expand Down
49 changes: 28 additions & 21 deletions components/mqtt/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import (

"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/app/shutdown"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/inx-app/pkg/nodebridge"
"github.com/iotaledger/inx-mqtt/pkg/broker"
"github.com/iotaledger/inx-mqtt/pkg/daemon"
"github.com/iotaledger/inx-mqtt/pkg/mqtt"
)

const (
APIRoute = "mqtt/v2"
)

func init() {
Component = &app.Component{
Name: "MQTT",
Expand All @@ -29,7 +27,7 @@ func init() {
type dependencies struct {
dig.In
NodeBridge *nodebridge.NodeBridge
Server *Server
Server *mqtt.Server
}

var (
Expand All @@ -41,31 +39,40 @@ func provide(c *dig.Container) error {

type inDeps struct {
dig.In
NodeBridge *nodebridge.NodeBridge
NodeBridge nodebridge.NodeBridge
*shutdown.ShutdownHandler
}

return c.Provide(func(deps inDeps) (*Server, error) {
return NewServer(
return c.Provide(func(deps inDeps) (*mqtt.Server, error) {
broker, err := broker.NewBroker(
broker.WithBufferSize(ParamsMQTT.BufferSize),
broker.WithBufferBlockSize(ParamsMQTT.BufferBlockSize),
broker.WithMaxTopicSubscriptionsPerClient(ParamsMQTT.Subscriptions.MaxTopicSubscriptionsPerClient),
broker.WithTopicCleanupThresholdCount(ParamsMQTT.Subscriptions.TopicsCleanupThresholdCount),
broker.WithTopicCleanupThresholdRatio(ParamsMQTT.Subscriptions.TopicsCleanupThresholdRatio),
broker.WithWebsocketEnabled(ParamsMQTT.Websocket.Enabled),
broker.WithWebsocketBindAddress(ParamsMQTT.Websocket.BindAddress),
broker.WithTCPEnabled(ParamsMQTT.TCP.Enabled),
broker.WithTCPBindAddress(ParamsMQTT.TCP.BindAddress),
broker.WithTCPAuthEnabled(ParamsMQTT.TCP.Auth.Enabled),
broker.WithTCPAuthPasswordSalt(ParamsMQTT.TCP.Auth.PasswordSalt),
broker.WithTCPAuthUsers(ParamsMQTT.TCP.Auth.Users),
broker.WithTCPTLSEnabled(ParamsMQTT.TCP.TLS.Enabled),
broker.WithTCPTLSCertificatePath(ParamsMQTT.TCP.TLS.CertificatePath),
broker.WithTCPTLSPrivateKeyPath(ParamsMQTT.TCP.TLS.PrivateKeyPath),
)
if err != nil {
return nil, ierrors.Wrap(err, "failed to create MQTT broker")
}

return mqtt.NewServer(
Component.Logger(),
deps.NodeBridge,
broker,
deps.ShutdownHandler,
mqtt.WithBufferSize(ParamsMQTT.BufferSize),
mqtt.WithBufferBlockSize(ParamsMQTT.BufferBlockSize),
mqtt.WithMaxTopicSubscriptionsPerClient(ParamsMQTT.Subscriptions.MaxTopicSubscriptionsPerClient),
mqtt.WithTopicCleanupThresholdCount(ParamsMQTT.Subscriptions.TopicsCleanupThresholdCount),
mqtt.WithTopicCleanupThresholdRatio(ParamsMQTT.Subscriptions.TopicsCleanupThresholdRatio),
mqtt.WithWebsocketEnabled(ParamsMQTT.Websocket.Enabled),
mqtt.WithWebsocketBindAddress(ParamsMQTT.Websocket.BindAddress),
mqtt.WithWebsocketAdvertiseAddress(ParamsMQTT.Websocket.AdvertiseAddress),
mqtt.WithTCPEnabled(ParamsMQTT.TCP.Enabled),
mqtt.WithTCPBindAddress(ParamsMQTT.TCP.BindAddress),
mqtt.WithTCPAuthEnabled(ParamsMQTT.TCP.Auth.Enabled),
mqtt.WithTCPAuthPasswordSalt(ParamsMQTT.TCP.Auth.PasswordSalt),
mqtt.WithTCPAuthUsers(ParamsMQTT.TCP.Auth.Users),
mqtt.WithTCPTLSEnabled(ParamsMQTT.TCP.TLS.Enabled),
mqtt.WithTCPTLSCertificatePath(ParamsMQTT.TCP.TLS.CertificatePath),
mqtt.WithTCPTLSPrivateKeyPath(ParamsMQTT.TCP.TLS.PrivateKeyPath),
)
})
}
Expand Down
Loading
Loading