Merge pull request #182 from OktopUSP/dev

init ws + add new readme section
This commit is contained in:
Leandro Antônio Farias Machado 2024-01-23 21:39:35 -03:00 committed by GitHub
commit d2b0af5ace
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 97 additions and 9 deletions

View File

@ -7,7 +7,7 @@
</li> </li>
</ul> </ul>
<p> <p>
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.
</p> </p>
<ul> <ul>
<li> <li>
@ -170,8 +170,6 @@ Currently, telecommunications giants and startups, publishing new software daily
</li> </li>
</ul> </ul>
-------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------
<ul><li><h4>Infrastructure:</h4></li></ul> <ul><li><h4>Infrastructure:</h4></li></ul>
@ -226,7 +224,7 @@ leandro@leandro-laptop:~$ cd oktopus/backend/services/socketio && npm i && npm s
leandro@leandro-laptop:~$ cd oktopus/frontend && npm i && npm run dev</pre> leandro@leandro-laptop:~$ cd oktopus/frontend && npm i && npm run dev</pre>
</li> </li>
</ul> </ul>
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.
</li> </li>
<li> <li>
<h4>Device test agent (obuspa):</h4> <h4>Device test agent (obuspa):</h4>
@ -245,6 +243,16 @@ OBS: Do not use those instructions in production. To implement the project in pr
-------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------
<ul><li><h4>Sponsors:</h4></li></ul>
<ul><li><h4>Companies that use Oktopus:</h4></li></ul>
<a href="https://www.inango.com/"><img src="https://github.com/OktopUSP/oktopus/assets/83298718/3b3e65d9-33fa-46c4-8b24-f9e2a84a04a6" width="125px"/></a>
<p>If you'd like to know how to donate, start a partnership or somehow to contribute to the project, email <a href="">leandro@oktopustr369.com</a>, 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.
--------------------------------------------------------------------------------------------------------------------------------------------------------
<ul> <ul>
<li> <li>
<h4>Roadmap:</h4> <h4>Roadmap:</h4>

View File

@ -4,11 +4,6 @@ import (
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"flag" "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" "io/ioutil"
"log" "log"
"os" "os"
@ -16,6 +11,12 @@ import (
"strings" "strings"
"syscall" "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/hooks/auth"
"github.com/mochi-co/mqtt/v2/listeners" "github.com/mochi-co/mqtt/v2/listeners"
) )
@ -145,6 +146,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Println("Websockets is running without TLS at port " + *wsAddr)
} }
if *infoAddr != "" { if *infoAddr != "" {

View File

@ -0,0 +1,9 @@
package main
import (
"github.com/OktopUSP/oktopus/ws/internal/ws"
)
func main() {
ws.StartNewServer()
}

View File

@ -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

View File

@ -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=

View File

@ -0,0 +1,53 @@
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) {
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)
}
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)
}
}