hashkey from inspecting raw
This commit is contained in:
30
src/adapt.go
30
src/adapt.go
@@ -8,30 +8,44 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func adapt(ctx context.Context, config Config, conn net.Conn) error {
|
func adapt(ctx context.Context, config Config, conn net.Conn) error {
|
||||||
reader := bufio.NewReader(conn)
|
reader := bufio.NewReader(conn)
|
||||||
|
|
||||||
|
alpha := regexp.MustCompile(`[a-zA-Z]`)
|
||||||
|
parts := regexp.MustCompile(`(.*?)\r\n*`)
|
||||||
|
|
||||||
for ctx.Err() == nil {
|
for ctx.Err() == nil {
|
||||||
if done, err := func() (bool, error) {
|
if done, err := func() (bool, error) {
|
||||||
raw, message, err := readMessage(reader)
|
raw, err := readMessage(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
log.Printf("routing: %q (%+v)", raw, message)
|
log.Printf("routing: %q", raw)
|
||||||
|
|
||||||
if len(message) > 0 && message[0].(string) == "COMMAND" {
|
if len(raw) > 0 {
|
||||||
fmt.Fprintf(conn, "*0\r\n")
|
hashKey := ""
|
||||||
} else if len(raw) > 0 && len(message) > 0 {
|
if matches := parts.FindAllSubmatch(raw, 5); len(matches) > 0 {
|
||||||
hashKey := message[0].(string)
|
for i := range matches {
|
||||||
if len(message) > 1 {
|
if isTheCommand := alpha.Match(matches[i][0]); isTheCommand {
|
||||||
hashKey = message[1].(string)
|
for j := i + 1; j < len(matches); j++ {
|
||||||
|
if matches[j][0][0] == byte('$') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
hashKey = string(matches[j][1])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
log.Printf("hashkey %q", hashKey)
|
||||||
if err := config.WithConn(hashKey, func(forwardConn net.Conn) error {
|
if err := config.WithConn(hashKey, func(forwardConn net.Conn) error {
|
||||||
//log.Printf("forwarding %q", raw)
|
//log.Printf("forwarding %q", raw)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user