2017-04-01 04:19:50 +00:00
|
|
|
package server
|
2017-02-25 05:56:40 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-22 21:43:36 +00:00
|
|
|
"bufio"
|
2017-02-26 05:17:39 +00:00
|
|
|
"bytes"
|
|
|
|
"context"
|
2017-02-25 05:56:40 +00:00
|
|
|
"crypto/tls"
|
2017-02-26 05:17:39 +00:00
|
|
|
"encoding/hex"
|
2020-04-30 10:43:36 +00:00
|
|
|
"fmt"
|
2017-02-26 05:17:39 +00:00
|
|
|
"log"
|
|
|
|
"net"
|
2017-03-22 21:43:36 +00:00
|
|
|
"net/http"
|
2017-02-26 23:27:38 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2017-02-26 05:17:39 +00:00
|
|
|
"time"
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2020-04-28 07:16:16 +00:00
|
|
|
telebit "git.coolaj86.com/coolaj86/go-telebitd"
|
2020-04-30 05:52:44 +00:00
|
|
|
"git.coolaj86.com/coolaj86/go-telebitd/packer"
|
2020-05-01 05:47:46 +00:00
|
|
|
"git.coolaj86.com/coolaj86/go-telebitd/relay/api"
|
2020-04-30 05:52:44 +00:00
|
|
|
"git.coolaj86.com/coolaj86/go-telebitd/sni"
|
2020-05-01 05:47:46 +00:00
|
|
|
"git.coolaj86.com/coolaj86/go-telebitd/tunnel"
|
2017-02-25 05:56:40 +00:00
|
|
|
)
|
|
|
|
|
2017-02-26 18:35:06 +00:00
|
|
|
type contextKey string
|
|
|
|
|
2017-03-03 00:47:59 +00:00
|
|
|
//CtxConnectionTrack
|
2017-02-26 18:35:06 +00:00
|
|
|
const (
|
2020-05-01 05:47:46 +00:00
|
|
|
ctxServerStatus contextKey = "serverstatus"
|
2020-04-30 10:43:36 +00:00
|
|
|
ctxConfig contextKey = "tlsConfig"
|
2017-03-19 14:56:33 +00:00
|
|
|
ctxListenerRegistration contextKey = "listenerRegistration"
|
|
|
|
ctxConnectionTrack contextKey = "connectionTrack"
|
|
|
|
ctxWssHostName contextKey = "wsshostname"
|
|
|
|
ctxAdminHostName contextKey = "adminHostName"
|
|
|
|
ctxCancelCheck contextKey = "cancelcheck"
|
|
|
|
ctxLoadbalanceDefaultMethod contextKey = "lbdefaultmethod"
|
2020-05-01 05:47:46 +00:00
|
|
|
//ctxConnectionTable contextKey = "connectionTable"
|
2017-02-26 18:35:06 +00:00
|
|
|
)
|
|
|
|
|
2020-04-30 10:43:36 +00:00
|
|
|
// TODO isn't this restriction in the TLS lib?
|
|
|
|
// or are we just pre-checking for remote hosts?
|
|
|
|
type tlsScheme int
|
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
const (
|
2020-04-30 10:43:36 +00:00
|
|
|
encryptNone tlsScheme = iota
|
2017-02-26 05:17:39 +00:00
|
|
|
encryptSSLV2
|
|
|
|
encryptSSLV3
|
|
|
|
encryptTLS10
|
|
|
|
encryptTLS11
|
|
|
|
encryptTLS12
|
2020-04-30 10:43:36 +00:00
|
|
|
encryptTLS13
|
2017-02-26 05:17:39 +00:00
|
|
|
)
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2020-04-30 10:43:36 +00:00
|
|
|
// multiListenAndServe -- used to lisen for any https traffic on 443 (8443)
|
2017-02-26 05:17:39 +00:00
|
|
|
// - setup generic TCP listener, unencrypted TCP, with a Deadtime out
|
|
|
|
// - leaverage the wedgeConn to peek into the buffer.
|
|
|
|
// - if TLS, consume connection with TLS certbundle, pass to request identifier
|
|
|
|
// - else, just pass to the request identififer
|
2020-04-30 10:43:36 +00:00
|
|
|
func (mx *MPlexy) multiListenAndServe(ctx context.Context, listenerRegistration *ListenerRegistration) {
|
2017-02-26 23:27:38 +00:00
|
|
|
loginfo.Println(":" + string(listenerRegistration.port))
|
2017-03-11 20:28:49 +00:00
|
|
|
cancelCheck := ctx.Value(ctxCancelCheck).(int)
|
2017-02-26 23:27:38 +00:00
|
|
|
|
|
|
|
listenAddr, err := net.ResolveTCPAddr("tcp", ":"+strconv.Itoa(listenerRegistration.port))
|
2017-02-26 18:35:06 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
if nil != err {
|
|
|
|
loginfo.Println(err)
|
2017-02-25 05:56:40 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
ln, err := net.ListenTCP("tcp", listenAddr)
|
|
|
|
if err != nil {
|
|
|
|
loginfo.Println("unable to bind", err)
|
2017-02-26 23:27:38 +00:00
|
|
|
listenerRegistration.status = listenerFault
|
|
|
|
listenerRegistration.err = err
|
|
|
|
listenerRegistration.commCh <- listenerRegistration
|
2017-02-26 05:17:39 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 23:27:38 +00:00
|
|
|
listenerRegistration.status = listenerAdded
|
|
|
|
listenerRegistration.commCh <- listenerRegistration
|
|
|
|
|
2017-02-25 05:56:40 +00:00
|
|
|
for {
|
2017-02-26 05:17:39 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
loginfo.Println("Cancel signal hit")
|
|
|
|
return
|
|
|
|
default:
|
2017-03-11 20:28:49 +00:00
|
|
|
ln.SetDeadline(time.Now().Add(time.Duration(cancelCheck) * time.Second))
|
2017-02-26 05:17:39 +00:00
|
|
|
|
|
|
|
conn, err := ln.Accept()
|
|
|
|
|
|
|
|
if nil != err {
|
|
|
|
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-30 10:43:36 +00:00
|
|
|
fmt.Println("New connection from %v on %v", conn.LocalAddr(), conn.RemoteAddr())
|
|
|
|
|
|
|
|
// TODO maybe put these into something like mx.newConnCh and have an mx.Accept()?
|
2020-05-01 05:47:46 +00:00
|
|
|
wedgeConn := tunnel.NewWedgeConn(conn)
|
2020-04-30 10:43:36 +00:00
|
|
|
go mx.accept(ctx, wedgeConn)
|
2017-02-25 05:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 10:43:36 +00:00
|
|
|
//accept -
|
2017-02-26 05:17:39 +00:00
|
|
|
// - accept a wedgeConnection along with all the other required attritvues
|
|
|
|
// - peek into the buffer, determine TLS or unencrypted
|
2020-05-01 05:47:46 +00:00
|
|
|
// - if TSL, then terminate with a TLS endpoint, pass to acceptEcryptedStream
|
|
|
|
// - if clearText, pass to acceptPlainStream
|
|
|
|
func (mx *MPlexy) accept(ctx context.Context, wConn *tunnel.WedgeConn) {
|
2017-02-26 05:17:39 +00:00
|
|
|
peekCnt := 10
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
encryptMode := encryptNone
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
loginfo.Println("new conn", wConn, wConn.LocalAddr().String(), wConn.RemoteAddr().String())
|
2017-02-26 05:17:39 +00:00
|
|
|
peek, err := wConn.Peek(peekCnt)
|
|
|
|
if err != nil {
|
|
|
|
loginfo.Println("error while peeking")
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2017-02-26 05:17:39 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
//take a look for a TLS header.
|
|
|
|
if bytes.Contains(peek[0:0], []byte{0x80}) && bytes.Contains(peek[2:4], []byte{0x01, 0x03}) {
|
|
|
|
encryptMode = encryptSSLV2
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
} else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x00}) {
|
|
|
|
encryptMode = encryptSSLV3
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
} else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x01}) {
|
|
|
|
encryptMode = encryptTLS10
|
|
|
|
loginfo.Println("TLS10")
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
} else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x02}) {
|
|
|
|
encryptMode = encryptTLS11
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
} else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x03}) {
|
|
|
|
encryptMode = encryptTLS12
|
2020-04-30 10:43:36 +00:00
|
|
|
|
|
|
|
} else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x04}) {
|
|
|
|
encryptMode = encryptTLS13
|
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
}
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
if encryptMode == encryptSSLV2 {
|
2020-04-30 10:43:36 +00:00
|
|
|
loginfo.Println("<= SSLv2 is not accepted")
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2017-02-26 05:17:39 +00:00
|
|
|
return
|
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
}
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
if encryptMode == encryptNone {
|
|
|
|
loginfo.Println("Handle Unencrypted")
|
2020-05-01 05:47:46 +00:00
|
|
|
mx.acceptPlainStream(ctx, wConn, false)
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
loginfo.Println("Handle Encryption")
|
2020-05-01 05:47:46 +00:00
|
|
|
mx.acceptEncryptedStream(ctx, wConn)
|
|
|
|
}
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
func (mx *MPlexy) acceptEncryptedStream(ctx context.Context, wConn *tunnel.WedgeConn) {
|
|
|
|
// Peek at SNI (ServerName) from TLS Hello header
|
2017-03-11 20:28:49 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
peek, err := wConn.PeekAll()
|
2020-04-30 05:49:09 +00:00
|
|
|
if err != nil {
|
2020-05-01 05:47:46 +00:00
|
|
|
loginfo.Println("Bad socket: read error from", wConn.RemoteAddr(), err)
|
2020-04-30 05:49:09 +00:00
|
|
|
loginfo.Println(hex.Dump(peek[0:]))
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
sniHostName, err := sni.GetHostname(peek)
|
|
|
|
if err != nil {
|
2020-05-01 05:47:46 +00:00
|
|
|
loginfo.Println("Bad socket: no SNI from", wConn.RemoteAddr(), err)
|
2020-04-30 05:49:09 +00:00
|
|
|
loginfo.Println(err)
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
loginfo.Println("SNI:", sniHostName)
|
2017-02-26 05:17:39 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
if sniHostName == mx.wssHostName || sniHostName == mx.adminHostName {
|
|
|
|
// The TLS should be terminated and handled internally
|
|
|
|
tlsConfig := ctx.Value(ctxConfig).(*tls.Config)
|
|
|
|
conn := tls.Client(wConn, tlsConfig)
|
|
|
|
tlsWedgeConn := tunnel.NewWedgeConn(conn)
|
|
|
|
mx.acceptPlainStream(ctx, tlsWedgeConn, true)
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
2020-04-30 10:43:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
//oneConn := &oneConnListener{wConn}
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
// TLS remains intact and shall be routed downstream, wholesale
|
|
|
|
loginfo.Println("processing non terminating traffic", mx.wssHostName, sniHostName)
|
|
|
|
go mx.routeToTarget(ctx, wConn, sniHostName, "https")
|
2017-02-25 05:56:40 +00:00
|
|
|
}
|
2017-02-26 05:17:39 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
//acceptPlainStream --
|
2017-02-26 18:35:06 +00:00
|
|
|
// - we have an unencrypted stream connection with the ability to peek
|
|
|
|
// - attempt to identify HTTP
|
|
|
|
// - handle http
|
|
|
|
// - attempt to identify as WSS session
|
|
|
|
// - attempt to identify as ADMIN/API session
|
2017-03-02 03:02:20 +00:00
|
|
|
// - else handle as raw http
|
2017-02-26 18:35:06 +00:00
|
|
|
// - handle other?
|
2020-05-01 05:47:46 +00:00
|
|
|
func (mx *MPlexy) acceptPlainStream(ctx context.Context, wConn *tunnel.WedgeConn, encrypted bool) {
|
|
|
|
loginfo.Println("Plain Conn", wConn.LocalAddr().String(), wConn.RemoteAddr().String())
|
2017-02-26 18:35:06 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
// TODO couldn't reading everything be dangerous? Or is it limited to a single packet?
|
2017-02-26 18:40:10 +00:00
|
|
|
peek, err := wConn.PeekAll()
|
2017-02-26 05:17:39 +00:00
|
|
|
if err != nil {
|
2017-03-11 05:36:42 +00:00
|
|
|
loginfo.Println("error while peeking", err)
|
2017-02-26 18:35:06 +00:00
|
|
|
loginfo.Println(hex.Dump(peek[0:]))
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2017-02-26 05:17:39 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-30 10:43:36 +00:00
|
|
|
// TODO handle by TCP port as well
|
|
|
|
// (which needs a short read timeout since servers expect clients to say hello)
|
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
// HTTP Identifcation // CRLF
|
|
|
|
if !bytes.Contains(peek[:], []byte{0x0d, 0x0a}) {
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-26 18:35:06 +00:00
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
//string protocol
|
|
|
|
if !bytes.ContainsAny(peek[:], "HTTP/") {
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-26 18:35:06 +00:00
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
loginfo.Println("identified HTTP")
|
2017-02-26 23:27:38 +00:00
|
|
|
|
2020-04-30 05:49:09 +00:00
|
|
|
r, err := http.ReadRequest(bufio.NewReader(bytes.NewReader(peek)))
|
|
|
|
if err != nil {
|
|
|
|
loginfo.Println("identified as HTTP, failed request parsing", err)
|
2020-05-01 05:47:46 +00:00
|
|
|
wConn.Close()
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
if strings.Contains(r.Host, telebit.InvalidAdminDomain) {
|
|
|
|
loginfo.Println("admin")
|
|
|
|
// TODO mx.Admin.CheckRemoteIP(conn) here
|
|
|
|
// handle admin path
|
|
|
|
mx.AcceptAdminClient(wConn)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-30 10:43:36 +00:00
|
|
|
// TODO add newtypes
|
|
|
|
// TODO check if this is a websocket
|
2020-05-01 05:47:46 +00:00
|
|
|
_, err = mx.AuthorizeTarget(r)
|
2020-04-30 10:43:36 +00:00
|
|
|
if err == nil {
|
2020-04-30 05:49:09 +00:00
|
|
|
loginfo.Println("Valid WSS dected...sending to handler")
|
2020-05-01 05:47:46 +00:00
|
|
|
mx.AcceptTargetServer(wConn)
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
2017-02-26 18:35:06 +00:00
|
|
|
}
|
2020-04-30 10:43:36 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
// TODO sniHostName is the key to the route, which could also be a port or hostname
|
|
|
|
//traffic not terminating on the rvpn do not decrypt
|
|
|
|
loginfo.Println("processing non terminating traffic", mx.wssHostName, r.Host)
|
|
|
|
loginfo.Println(hex.Dump(peek))
|
|
|
|
if !encrypted {
|
|
|
|
// TODO request and cache http resources as a feature??
|
|
|
|
go mx.routeToTarget(ctx, wConn, r.Host, "http")
|
2020-04-30 05:49:09 +00:00
|
|
|
return
|
|
|
|
}
|
2020-05-01 05:47:46 +00:00
|
|
|
|
|
|
|
// This is not presently possible
|
|
|
|
loginfo.Println("impossible condition: local decryption of routable client", mx.wssHostName, r.Host)
|
|
|
|
go mx.routeToTarget(ctx, wConn, r.Host, "https")
|
2017-02-26 05:17:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
//routeToTarget -
|
2017-02-26 23:27:38 +00:00
|
|
|
// - get a wConn and start processing requests
|
2020-05-01 05:47:46 +00:00
|
|
|
func (mx *MPlexy) routeToTarget(ctx context.Context, extConn *tunnel.WedgeConn, hostname, service string) {
|
|
|
|
// TODO is this the right place to do this?
|
|
|
|
defer extConn.Close()
|
|
|
|
|
2017-03-20 00:04:47 +00:00
|
|
|
//connectionTracking := ctx.Value(ctxConnectionTrack).(*Tracking)
|
2020-05-01 05:47:46 +00:00
|
|
|
serverStatus := ctx.Value(ctxServerStatus).(*api.Status)
|
2017-02-26 23:27:38 +00:00
|
|
|
|
2017-03-03 00:47:59 +00:00
|
|
|
defer func() {
|
2017-03-20 00:04:47 +00:00
|
|
|
serverStatus.ExtConnectionUnregister(extConn)
|
2017-03-04 18:18:08 +00:00
|
|
|
extConn.Close()
|
2017-03-03 00:47:59 +00:00
|
|
|
}()
|
2017-02-26 23:27:38 +00:00
|
|
|
|
2017-03-11 05:36:42 +00:00
|
|
|
//find the connection by domain name
|
2017-03-20 00:04:47 +00:00
|
|
|
conn, ok := serverStatus.ConnectionTable.ConnByDomain(hostname)
|
2017-03-11 05:36:42 +00:00
|
|
|
if !ok {
|
|
|
|
//matching connection can not be found based on ConnByDomain
|
|
|
|
loginfo.Println("unable to match ", hostname, " to an existing connection")
|
|
|
|
//http.Error(, "Domain not supported", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
track := api.NewTrack(extConn, hostname)
|
2017-03-20 00:04:47 +00:00
|
|
|
serverStatus.ExtConnectionRegister(track)
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2017-03-30 19:28:00 +00:00
|
|
|
remoteStr := extConn.RemoteAddr().String()
|
|
|
|
loginfo.Println("Domain Accepted", hostname, remoteStr)
|
|
|
|
|
|
|
|
var header *packer.Header
|
|
|
|
if rAddr, rPort, err := net.SplitHostPort(remoteStr); err != nil {
|
|
|
|
loginfo.Println("unable to decode hostport", remoteStr, err)
|
|
|
|
} else if port, err := strconv.Atoi(rPort); err != nil {
|
|
|
|
loginfo.Printf("unable to parse port string %q: %v\n", rPort, err)
|
|
|
|
} else if header, err = packer.NewHeader(rAddr, port, service); err != nil {
|
|
|
|
loginfo.Println("unable to create packer header", err)
|
|
|
|
}
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2017-03-30 19:28:00 +00:00
|
|
|
if header == nil {
|
2017-03-11 05:36:42 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-26 23:27:38 +00:00
|
|
|
|
|
|
|
for {
|
2017-03-11 20:28:49 +00:00
|
|
|
buffer, err := extConn.PeekAll()
|
2017-02-26 23:27:38 +00:00
|
|
|
if err != nil {
|
2017-03-11 20:28:49 +00:00
|
|
|
loginfo.Println("unable to peekAll", err)
|
2017-02-26 23:27:38 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-03-11 20:28:49 +00:00
|
|
|
loginfo.Println("Before Packer", hex.Dump(buffer))
|
|
|
|
|
2017-03-30 19:28:00 +00:00
|
|
|
p := packer.NewPacker(header)
|
|
|
|
p.Data.AppendBytes(buffer)
|
2017-03-02 03:02:20 +00:00
|
|
|
buf := p.PackV1()
|
2017-02-26 23:27:38 +00:00
|
|
|
|
2017-03-20 00:04:47 +00:00
|
|
|
//loginfo.Println(hex.Dump(buf.Bytes()))
|
2017-03-11 05:36:42 +00:00
|
|
|
|
2017-03-20 00:04:47 +00:00
|
|
|
//Bundle up the send request and dispatch
|
2020-05-01 05:47:46 +00:00
|
|
|
sendTrack := api.NewSendTrack(buf.Bytes(), hostname)
|
2017-03-20 00:04:47 +00:00
|
|
|
serverStatus.SendExtRequest(conn, sendTrack)
|
2017-03-11 20:28:49 +00:00
|
|
|
|
2017-03-30 19:28:00 +00:00
|
|
|
cnt := len(buffer)
|
|
|
|
if _, err = extConn.Discard(cnt); err != nil {
|
2017-03-11 20:28:49 +00:00
|
|
|
loginfo.Println("unable to discard", cnt, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-26 23:27:38 +00:00
|
|
|
}
|
|
|
|
}
|