-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chaitanya Munukutla <[email protected]>
- Loading branch information
Showing
10 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package conn | ||
|
||
import "net" | ||
|
||
type TCPConnection struct { | ||
conn *net.TCPConn | ||
} | ||
|
||
func NewTCPConnection(conn *net.TCPConn) *TCPConnection { | ||
return &TCPConnection{conn: conn} | ||
} | ||
|
||
func (tc *TCPConnection) WriteMessage(data []byte) error { | ||
_, err := tc.conn.Write(data) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package conn | ||
|
||
import "github.com/gorilla/websocket" | ||
|
||
type WebsocketConnection struct { | ||
conn *websocket.Conn | ||
} | ||
|
||
func NewWebsocketConnection(conn *websocket.Conn) *WebsocketConnection { | ||
return &WebsocketConnection{conn: conn} | ||
} | ||
|
||
func (wc *WebsocketConnection) WriteMessage(data []byte) error { | ||
return wc.conn.WriteMessage(websocket.TextMessage, data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package events | ||
|
||
const Conn = "conn" | ||
|
||
type ConnEvent struct { | ||
Kind string `json:"kind"` | ||
ClientId string `json:"client_id"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package events | ||
|
||
const ConnAck = "connack" | ||
|
||
type ConnAckEvent struct { | ||
Kind string `json:"kind"` | ||
ClientId string `json:"client_id"` | ||
Status bool `json:"status"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package handlers | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/c16a/microq/broker" | ||
"github.com/c16a/microq/events" | ||
) | ||
|
||
func handleConn(message []byte, client *broker.ConnectedClient) error { | ||
var event events.ConnEvent | ||
err := json.Unmarshal(message, &event) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client.SetId(event.ClientId) | ||
subackEvent := &events.ConnAckEvent{ | ||
Kind: events.ConnAck, | ||
Status: true, | ||
ClientId: event.ClientId, | ||
} | ||
return client.WriteInterface(subackEvent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters