Data Written to the Channel

- added support for ConnByDomain which looks up existing WSS and registered domain
- passed connection table to External Listener
- on request, obtained hostname and map to domain, split the remote address and port (will go into an table eventually)
- look up the domain and find the WSS connection
- packed up the frame.
- sent down the channel.
This commit is contained in:
Henry Camacho 2017-02-13 20:36:01 -06:00
parent 604f1d0b03
commit 8a5ab4fe76
5 changed files with 50 additions and 4 deletions

View File

@ -51,6 +51,11 @@ func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress s
return
}
//SendCh -- property to sending channel
func (c *Connection) SendCh() chan []byte {
return c.send
}
func (c *Connection) addIn(num int64) {
c.bytesIn = c.bytesIn + num
}

View File

@ -29,6 +29,12 @@ func NewTable() (p *Table) {
return
}
//ConnByDomain -- Obtains a connection from a domain announcement.
func (c *Table) ConnByDomain(domain string) (conn *Connection, ok bool) {
conn, ok = c.domains[domain]
return
}
//Run -- Execute
func (c *Table) Run() {
loginfo.Println("ConnectionTable starting")

View File

@ -5,11 +5,16 @@ import (
"net"
"net/http"
"net/http/httputil"
"strconv"
"strings"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/connection"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/packer"
)
//LaunchWebRequestExternalListener - starts up extern http listeners, gets request and prep's to hand it off inside.
func LaunchWebRequestExternalListener(serverBinding *string) {
func LaunchWebRequestExternalListener(serverBinding *string, connectionTable *connection.Table) {
loginfo.Println("starting WebRequestExternal Listener ", *serverBinding)
mux := http.NewServeMux()
@ -25,8 +30,33 @@ func LaunchWebRequestExternalListener(serverBinding *string) {
loginfo.Printf("%q", dump)
}
}
hostname := r.Host
if strings.Contains(hostname, ":") {
arr := strings.Split(hostname, ":")
hostname = arr[0]
}
remoteSplit := strings.Split(r.RemoteAddr, ":")
rAddr := remoteSplit[0]
rPort := remoteSplit[1]
if conn, ok := connectionTable.ConnByDomain(hostname); !ok {
//matching connection can not be found based on ConnByDomain
loginfo.Println("unable to match ", hostname, " to an existing connection")
http.Error(w, "Domain not supported", http.StatusBadRequest)
} else {
loginfo.Println(conn, rAddr, rPort)
p := packer.NewPacker()
p.Header.SetAddress("127.0.0.2")
p.Header.Port, err = strconv.Atoi(rPort)
p.Data.AppendBytes(dump)
buf := p.PackV1()
conn.SendCh() <- buf.Bytes()
}
}
})
s := &http.Server{
Addr: *serverBinding,

View File

@ -17,3 +17,8 @@ func (p packerData) AppendString(dataString string) (n int, err error) {
n, err = p.buffer.WriteString(dataString)
return
}
func (p packerData) AppendBytes(dataBytes []byte) (n int, err error) {
n, err = p.buffer.Write(dataBytes)
return
}

View File

@ -56,7 +56,7 @@ func Run() {
connectionTable = connection.NewTable()
go connectionTable.Run()
go client.LaunchClientListener(connectionTable, &secretKey, &argServerBinding)
go external.LaunchWebRequestExternalListener(&argServerExternalBinding)
go external.LaunchWebRequestExternalListener(&argServerExternalBinding, connectionTable)
err := admin.LaunchAdminListener(&argServerAdminBinding)
if err != nil {