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:
parent
604f1d0b03
commit
8a5ab4fe76
|
@ -51,6 +51,11 @@ func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress s
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SendCh -- property to sending channel
|
||||||
|
func (c *Connection) SendCh() chan []byte {
|
||||||
|
return c.send
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Connection) addIn(num int64) {
|
func (c *Connection) addIn(num int64) {
|
||||||
c.bytesIn = c.bytesIn + num
|
c.bytesIn = c.bytesIn + num
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,12 @@ func NewTable() (p *Table) {
|
||||||
return
|
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
|
//Run -- Execute
|
||||||
func (c *Table) Run() {
|
func (c *Table) Run() {
|
||||||
loginfo.Println("ConnectionTable starting")
|
loginfo.Println("ConnectionTable starting")
|
||||||
|
|
|
@ -5,11 +5,16 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"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.
|
//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)
|
loginfo.Println("starting WebRequestExternal Listener ", *serverBinding)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
@ -25,8 +30,33 @@ func LaunchWebRequestExternalListener(serverBinding *string) {
|
||||||
loginfo.Printf("%q", dump)
|
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{
|
s := &http.Server{
|
||||||
Addr: *serverBinding,
|
Addr: *serverBinding,
|
||||||
|
|
|
@ -17,3 +17,8 @@ func (p packerData) AppendString(dataString string) (n int, err error) {
|
||||||
n, err = p.buffer.WriteString(dataString)
|
n, err = p.buffer.WriteString(dataString)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p packerData) AppendBytes(dataBytes []byte) (n int, err error) {
|
||||||
|
n, err = p.buffer.Write(dataBytes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func Run() {
|
||||||
connectionTable = connection.NewTable()
|
connectionTable = connection.NewTable()
|
||||||
go connectionTable.Run()
|
go connectionTable.Run()
|
||||||
go client.LaunchClientListener(connectionTable, &secretKey, &argServerBinding)
|
go client.LaunchClientListener(connectionTable, &secretKey, &argServerBinding)
|
||||||
go external.LaunchWebRequestExternalListener(&argServerExternalBinding)
|
go external.LaunchWebRequestExternalListener(&argServerExternalBinding, connectionTable)
|
||||||
|
|
||||||
err := admin.LaunchAdminListener(&argServerAdminBinding)
|
err := admin.LaunchAdminListener(&argServerAdminBinding)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue