From 48e03db9607d3d72398b5169064a0d385d73360c Mon Sep 17 00:00:00 2001 From: leandrofars Date: Tue, 16 Jan 2024 23:45:56 -0300 Subject: [PATCH 1/8] initial websockets server --- backend/services/ws/cmd/main.go | 9 +++++ backend/services/ws/go.mod | 10 ++++++ backend/services/ws/go.sum | 6 ++++ backend/services/ws/internal/ws/ws.go | 48 +++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 backend/services/ws/cmd/main.go create mode 100644 backend/services/ws/go.mod create mode 100644 backend/services/ws/go.sum create mode 100644 backend/services/ws/internal/ws/ws.go diff --git a/backend/services/ws/cmd/main.go b/backend/services/ws/cmd/main.go new file mode 100644 index 0000000..4b21c5b --- /dev/null +++ b/backend/services/ws/cmd/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "github.com/OktopUSP/oktopus/ws/internal/ws" +) + +func main() { + ws.StartNewServer() +} diff --git a/backend/services/ws/go.mod b/backend/services/ws/go.mod new file mode 100644 index 0000000..5fdd0ba --- /dev/null +++ b/backend/services/ws/go.mod @@ -0,0 +1,10 @@ +module github.com/OktopUSP/oktopus/ws + +go 1.21.6 + +require ( + github.com/gorilla/mux v1.8.1 + github.com/gorilla/websocket v1.5.1 +) + +require golang.org/x/net v0.17.0 // indirect diff --git a/backend/services/ws/go.sum b/backend/services/ws/go.sum new file mode 100644 index 0000000..8b329b1 --- /dev/null +++ b/backend/services/ws/go.sum @@ -0,0 +1,6 @@ +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= diff --git a/backend/services/ws/internal/ws/ws.go b/backend/services/ws/internal/ws/ws.go new file mode 100644 index 0000000..c9b18fc --- /dev/null +++ b/backend/services/ws/internal/ws/ws.go @@ -0,0 +1,48 @@ +package ws + +import ( + "log" + "net/http" + + "github.com/gorilla/mux" + "github.com/gorilla/websocket" +) + +var upgrader = websocket.Upgrader{ + ReadBufferSize: 1024, + WriteBufferSize: 1024, + CheckOrigin: func(r *http.Request) bool { return true }, +} + +func StartNewServer() { + r := mux.NewRouter() + r.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { + + conn, err := upgrader.Upgrade(w, r, nil) + if err != nil { + log.Println(err) + } + for { + messageType, p, err := conn.ReadMessage() + if err != nil { + log.Println(err) + return + } + log.Println(string(p)) + + if err := conn.WriteMessage(messageType, p); err != nil { + log.Println(err) + return + } + + } + }) + + log.Println("Websockets server running") + + err := http.ListenAndServe(":8080", r) + if err != nil { + log.Fatal("ListenAndServe: ", err) + } + +} From 46c50f5985e287184d72fc8c8b6023f6b9861d6a Mon Sep 17 00:00:00 2001 From: leandrofars Date: Wed, 17 Jan 2024 23:37:53 -0300 Subject: [PATCH 2/8] docs(readme): update --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d80b572..926062c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@

-This repository aims to promote the development of a multi-vendor management platform for IoTs. Any device that follows the TR-369 protocol can be managed. The main objective is to facilitate and unify device management, which generates countless benefits for the end user and service providers, suppressing the demands that today's technologies require: device interconnection, data collection, speed, availability and more. +This repository aims to promote the development of a multi-vendor management platform for CPEs and IoTs. Any device that follows the TR-369 protocol can be managed. The main objective is to facilitate and unify device management, which generates countless benefits for the end user and service providers, suppressing the demands that today's technologies require: device interconnection, data collection, speed, availability and more.

+-------------------------------------------------------------------------------------------------------------------------------------------------------- + +

If you'd like to know how to donate to the project, email leandro@oktopustr369.com or hit the Sponsor button in this page. Every contribution is welcome, and the resources will help the project to move on.

+ + +

If you are a user of this project and would like your company logo displayed above here, please email leandro@oktopustr369.com with your request.

-------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -226,7 +232,7 @@ leandro@leandro-laptop:~$ cd oktopus/backend/services/socketio && npm i && npm s leandro@leandro-laptop:~$ cd oktopus/frontend && npm i && npm run dev -OBS: Do not use those instructions in production. To implement the project in production you might use more resources that are already avaiable in Oktopus, but would take longer to explain in this README. Soon, there will be more help and explanations about those extra needed configs. +
  • Device test agent (obuspa):

    From 37a176c01a9af387ee5c8a6c27f37aa92d8a4f6a Mon Sep 17 00:00:00 2001 From: leandrofars Date: Wed, 17 Jan 2024 23:40:32 -0300 Subject: [PATCH 3/8] docs(readme): small add to sponsors topic --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 926062c..3dfdab3 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ Currently, telecommunications giants and startups, publishing new software daily --------------------------------------------------------------------------------------------------------------------------------------------------------
    • Sponsors:

    -

    If you'd like to know how to donate to the project, email leandro@oktopustr369.com or hit the Sponsor button in this page. Every contribution is welcome, and the resources will help the project to move on.

    +

    If you'd like to know how to donate to the project, email leandro@oktopustr369.com or hit the Sponsor button in this page. Every contribution is welcome, and the resources will help the project to move on. In case you want, your photo or company logo can be displayed above.

    • Companies that use:

    If you are a user of this project and would like your company logo displayed above here, please email leandro@oktopustr369.com with your request.

    From 4408cfc0a96c036879839631412d301b752896fa Mon Sep 17 00:00:00 2001 From: leandrofars Date: Wed, 17 Jan 2024 23:46:20 -0300 Subject: [PATCH 4/8] docs(readme): fix mail link style --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3dfdab3..adb9d50 100644 --- a/README.md +++ b/README.md @@ -173,10 +173,10 @@ Currently, telecommunications giants and startups, publishing new software daily --------------------------------------------------------------------------------------------------------------------------------------------------------
    • Sponsors:

    -

    If you'd like to know how to donate to the project, email leandro@oktopustr369.com or hit the Sponsor button in this page. Every contribution is welcome, and the resources will help the project to move on. In case you want, your photo or company logo can be displayed above.

    +

    If you'd like to know how to donate to the project, email leandro@oktopustr369.com or hit the Sponsor button in this page. Every contribution is welcome, and the resources will help the project to move on. In case you want, your photo or company logo can be displayed above.

    • Companies that use:

    -

    If you are a user of this project and would like your company logo displayed above here, please email leandro@oktopustr369.com with your request.

    +

    If you are a user of this project and would like your company logo displayed above here, please email leandro@oktopustr369.com with your request.

    -------------------------------------------------------------------------------------------------------------------------------------------------------- From 46488fb3d5f8575318a52d788e4779d4e8572830 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Thu, 18 Jan 2024 22:36:09 -0300 Subject: [PATCH 5/8] chore(mochi): log websockets running info --- backend/services/mochi/cmd/main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/services/mochi/cmd/main.go b/backend/services/mochi/cmd/main.go index 931cb87..3383a5d 100644 --- a/backend/services/mochi/cmd/main.go +++ b/backend/services/mochi/cmd/main.go @@ -4,11 +4,6 @@ import ( "bytes" "crypto/tls" "flag" - rv8 "github.com/go-redis/redis/v8" - "github.com/mochi-co/mqtt/v2" - "github.com/mochi-co/mqtt/v2/hooks/storage/redis" - "github.com/mochi-co/mqtt/v2/packets" - "github.com/rs/zerolog" "io/ioutil" "log" "os" @@ -16,6 +11,12 @@ import ( "strings" "syscall" + rv8 "github.com/go-redis/redis/v8" + "github.com/mochi-co/mqtt/v2" + "github.com/mochi-co/mqtt/v2/hooks/storage/redis" + "github.com/mochi-co/mqtt/v2/packets" + "github.com/rs/zerolog" + "github.com/mochi-co/mqtt/v2/hooks/auth" "github.com/mochi-co/mqtt/v2/listeners" ) @@ -145,6 +146,7 @@ func main() { if err != nil { log.Fatal(err) } + log.Println("Websockets is running without TLS at port " + *wsAddr) } if *infoAddr != "" { From a60f0f0a288d12e2ea1c50ec22564043c7f48cca Mon Sep 17 00:00:00 2001 From: leandrofars Date: Thu, 18 Jan 2024 22:51:08 -0300 Subject: [PATCH 6/8] feat: add usp webscokets header --- backend/services/ws/internal/ws/ws.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/services/ws/internal/ws/ws.go b/backend/services/ws/internal/ws/ws.go index c9b18fc..bdb852a 100644 --- a/backend/services/ws/internal/ws/ws.go +++ b/backend/services/ws/internal/ws/ws.go @@ -18,7 +18,12 @@ func StartNewServer() { r := mux.NewRouter() r.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { - conn, err := upgrader.Upgrade(w, r, nil) + header := http.Header{ + "Sec-Websocket-Protocol": {"v1.usp"}, + "Sec-Websocket-Version": {"13"}, + } + + conn, err := upgrader.Upgrade(w, r, header) if err != nil { log.Println(err) } From 72b12233948358a1e3a4a002df066af16771ab6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20Ant=C3=B4nio=20Farias=20Machado?= <83298718+leandrofars@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:33:26 -0300 Subject: [PATCH 7/8] docs(readme): add companies that use section --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index adb9d50..97df56b 100644 --- a/README.md +++ b/README.md @@ -170,14 +170,6 @@ Currently, telecommunications giants and startups, publishing new software daily
  • --------------------------------------------------------------------------------------------------------------------------------------------------------- - - -

    If you'd like to know how to donate to the project, email leandro@oktopustr369.com or hit the Sponsor button in this page. Every contribution is welcome, and the resources will help the project to move on. In case you want, your photo or company logo can be displayed above.

    - - -

    If you are a user of this project and would like your company logo displayed above here, please email leandro@oktopustr369.com with your request.

    - -------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -251,6 +243,16 @@ leandro@leandro-laptop:~$ cd oktopus/frontend && npm i && npm run dev -------------------------------------------------------------------------------------------------------------------------------------------------------- + + + + + + +

    If you'd like to know how to donate, start a partnership or somehow to contribute to the project, email leandro@oktopustr369.com, every contribution is welcome, and the resources will help the project to move on. Also, if your company uses this project and you'd like your logo to appear up here, contact us. + +-------------------------------------------------------------------------------------------------------------------------------------------------------- +