updated ipbl
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-05-27 18:36:15 +02:00
parent e5658ff99f
commit 670f8a6f9f
4 changed files with 29 additions and 23 deletions

View File

@ -236,6 +236,7 @@ func QueryInfo(client *http.Client, ip string) (query QueryIP, err error) {
res, err := client.Do(req)
if err != nil {
log.Println(err)
return
}
data, err := io.ReadAll(res.Body)
if err != nil {

View File

@ -8,32 +8,32 @@ import (
"golang.org/x/net/websocket"
)
var WebSocketChannel = make(chan models.APIEvent, 100)
var WebSocketChannelDone = make(chan bool)
var webSocketChannel = make(chan models.APIEvent, 100)
var webSocketChannelDone = make(chan bool)
var LISTENERS map[string]*ConnectionInfo
var listeners map[string]*connectionInfo
func Init(cfg *config.Config) {
LISTENERS = make(map[string]*ConnectionInfo)
listeners = make(map[string]*connectionInfo)
}
func WelcomeAgents(ws *websocket.Conn, welcome WSWelcome, t string) {
connectinfo, ok := LISTENERS[welcome.Hostname]
func welcomeAgents(ws *websocket.Conn, welcome wsWelcome, t string) {
connectinfo, ok := listeners[welcome.Hostname]
if !ok {
switch t {
case "ps":
connectinfo := ConnectionInfo{
connectinfo := connectionInfo{
ConnectionPS: ws,
InitDate: time.Now(),
}
LISTENERS[welcome.Hostname] = &connectinfo
listeners[welcome.Hostname] = &connectinfo
case "rr":
connectinfo := ConnectionInfo{
connectinfo := connectionInfo{
ConnectionRR: ws,
InitDate: time.Now(),
}
LISTENERS[welcome.Hostname] = &connectinfo
listeners[welcome.Hostname] = &connectinfo
}
} else {
switch t {
@ -46,22 +46,25 @@ func WelcomeAgents(ws *websocket.Conn, welcome WSWelcome, t string) {
}
func gcConnOnError(ws *websocket.Conn) (err error) {
for index, value := range LISTENERS {
if value.ConnectionPS == ws || value.ConnectionRR == ws {
for index, value := range listeners {
if value.ConnectionPS == ws {
value.ConnectionPS.Close()
delete(listeners, index)
} else if value.ConnectionRR == ws {
value.ConnectionRR.Close()
delete(LISTENERS, index)
delete(listeners, index)
}
}
return err
}
type ConnectionInfo struct {
type connectionInfo struct {
ConnectionPS *websocket.Conn
ConnectionRR *websocket.Conn
InitDate time.Time
}
type WSWelcome struct {
// WSWelcome
type wsWelcome struct {
Hostname string
}

View File

@ -10,11 +10,12 @@ import (
"golang.org/x/net/websocket"
)
// HandleWSPS handle pub sub flows
func HandleWSPS(c echo.Context, cfg *config.Config) (err error) {
websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
var welcome = WSWelcome{}
var welcome = wsWelcome{}
var msg []byte
err := websocket.Message.Receive(ws, &msg)
@ -26,7 +27,7 @@ func HandleWSPS(c echo.Context, cfg *config.Config) (err error) {
if err != nil {
log.Println(err)
} else {
WelcomeAgents(ws, welcome, "ps")
welcomeAgents(ws, welcome, "ps")
}
err = websocket.Message.Receive(ws, "OK")

View File

@ -10,11 +10,12 @@ import (
"golang.org/x/net/websocket"
)
// HandleWSRR handle req rep flows
func HandleWSRR(c echo.Context, cfg *config.Config) error {
websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
var welcome = WSWelcome{}
var welcome = wsWelcome{}
var msg []byte
err := websocket.Message.Receive(ws, &msg)
@ -24,7 +25,7 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
err = json.Unmarshal(msg, &welcome)
if err == nil {
WelcomeAgents(ws, welcome, "rr")
welcomeAgents(ws, welcome, "rr")
}
var lastip string
@ -51,7 +52,7 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
switch apievent.MsgType {
case "bootstrap":
log.Printf("bootstrap: %s\n", apievent.Hostname)
for index, value := range LISTENERS {
for index, value := range listeners {
if index != apievent.Hostname && value.ConnectionPS != nil {
err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil {
@ -70,7 +71,7 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
log.Println(err)
}
for _, value := range LISTENERS {
for _, value := range listeners {
if value.ConnectionPS != nil {
err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil {
@ -81,7 +82,7 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
}
log.Printf("ws: Inserted event")
case "init":
for _, value := range LISTENERS {
for _, value := range listeners {
if value.ConnectionPS != nil {
err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil {
@ -104,7 +105,7 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(ws, "OK")
if err != nil {
//gcConn(ws, "rr")
log.Println(LISTENERS)
log.Println(listeners)
return
}
*/