This commit is contained in:
Josh Baker 2017-01-13 08:45:55 -07:00
commit 23e846e9df
5 changed files with 51 additions and 20 deletions

7
.gitignore vendored
View File

@ -2,8 +2,9 @@
tile38-* tile38-*
!cmd/tile38-* !cmd/tile38-*
data*/ data*/
coverage.out coverage.out
packages/ packages/
# Ignore VS Code folder # Ignore IDE folders
.vscode/ .idea/
.vscode/

View File

@ -32,6 +32,9 @@ var (
quiet bool quiet bool
) )
// TODO: Set to false in 2.*
var httpTransport bool = true
// Fire up a webhook test server by using the --webhook-http-consumer-port // Fire up a webhook test server by using the --webhook-http-consumer-port
// for example // for example
// $ ./tile38-server --webhook-http-consumer-port 9999 // $ ./tile38-server --webhook-http-consumer-port 9999
@ -106,6 +109,17 @@ func main() {
case "--dev", "-dev": case "--dev", "-dev":
devMode = true devMode = true
continue continue
case "--http-transport":
i++
if i < len(os.Args) {
switch strings.ToLower(os.Args[i]) {
case "1", "true", "yes":
httpTransport = true
case "0", "false", "no":
httpTransport = false
}
continue
}
} }
nargs = append(nargs, os.Args[i]) nargs = append(nargs, os.Args[i])
} }
@ -118,6 +132,7 @@ func main() {
flag.BoolVar(&quiet, "q", false, "Quiet logging. Totally silent.") flag.BoolVar(&quiet, "q", false, "Quiet logging. Totally silent.")
flag.BoolVar(&veryVerbose, "vv", false, "Enable very verbose logging.") flag.BoolVar(&veryVerbose, "vv", false, "Enable very verbose logging.")
flag.Parse() flag.Parse()
var logw io.Writer = os.Stderr var logw io.Writer = os.Stderr
if quiet { if quiet {
logw = ioutil.Discard logw = ioutil.Discard
@ -138,6 +153,11 @@ func main() {
gitsha = "" gitsha = ""
} }
httpTransportEnabled := "Enabled"
if !httpTransport {
httpTransportEnabled = "Disabled"
}
// _____ _ _ ___ ___ // _____ _ _ ___ ___
// |_ _|_| |___|_ | . | // |_ _|_| |___|_ | . |
// | | | | | -_|_ | . | // | | | | | -_|_ | . |
@ -148,12 +168,12 @@ func main() {
| | | | | |
|____ | _ | Tile38 %s%s %d bit (%s/%s) |____ | _ | Tile38 %s%s %d bit (%s/%s)
| | | %sPort: %d, PID: %d | | | %sPort: %d, PID: %d
|____ | _ | |____ | _ | HTTP & WebSocket transports: %s
| | | tile38.com | | |
|_______|_______| |_______|_______| tile38.com
`+"\n", core.Version, gitsha, strconv.IntSize, runtime.GOARCH, runtime.GOOS, hostd, port, os.Getpid()) `+"\n", core.Version, gitsha, strconv.IntSize, runtime.GOARCH, runtime.GOOS, hostd, port, os.Getpid(), httpTransportEnabled)
if err := controller.ListenAndServe(host, port, dir); err != nil { if err := controller.ListenAndServe(host, port, dir, httpTransport); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

View File

@ -100,10 +100,10 @@ type Controller struct {
} }
// ListenAndServe starts a new tile38 server // ListenAndServe starts a new tile38 server
func ListenAndServe(host string, port int, dir string) error { func ListenAndServe(host string, port int, dir string, http bool) error {
return ListenAndServeEx(host, port, dir, nil) return ListenAndServeEx(host, port, dir, nil, http)
} }
func ListenAndServeEx(host string, port int, dir string, ln *net.Listener) error { func ListenAndServeEx(host string, port int, dir string, ln *net.Listener, http bool) error {
log.Infof("Server started, Tile38 version %s, git %s", core.Version, core.GitSHA) log.Infof("Server started, Tile38 version %s, git %s", core.Version, core.GitSHA)
c := &Controller{ c := &Controller{
host: host, host: host,
@ -221,7 +221,7 @@ func ListenAndServeEx(host string, port int, dir string, ln *net.Listener) error
delete(c.conns, conn) delete(c.conns, conn)
c.mu.Unlock() c.mu.Unlock()
} }
return server.ListenAndServe(host, port, protected, handler, opened, closed, ln) return server.ListenAndServe(host, port, protected, handler, opened, closed, ln, http)
} }
func (c *Controller) watchMemory() { func (c *Controller) watchMemory() {

View File

@ -21,21 +21,21 @@ Tile38 is running in protected mode because protected mode is enabled, no host
address was specified, no authentication password is requested to clients. In address was specified, no authentication password is requested to clients. In
this mode connections are only accepted from the loopback interface. If you this mode connections are only accepted from the loopback interface. If you
want to connect from external computers to Tile38 you may adopt one of the want to connect from external computers to Tile38 you may adopt one of the
following solutions: following solutions:
1) Disable protected mode by sending the command 'CONFIG SET protected-mode no' 1) Disable protected mode by sending the command 'CONFIG SET protected-mode no'
from the loopback interface by connecting to Tile38 from the same host from the loopback interface by connecting to Tile38 from the same host
the server is running, however MAKE SURE Tile38 is not publicly accessible the server is running, however MAKE SURE Tile38 is not publicly accessible
from internet if you do so. Use CONFIG REWRITE to make this change from internet if you do so. Use CONFIG REWRITE to make this change
permanent. permanent.
2) Alternatively you can just disable the protected mode by editing the Tile38 2) Alternatively you can just disable the protected mode by editing the Tile38
configuration file, and setting the 'protected-mode' option to 'no', and configuration file, and setting the 'protected-mode' option to 'no', and
then restarting the server. then restarting the server.
3) If you started the server manually just for testing, restart it with the 3) If you started the server manually just for testing, restart it with the
'--protected-mode no' option. '--protected-mode no' option.
4) Use a host address or an authentication password. 4) Use a host address or an authentication password.
NOTE: You only need to do one of the above things in order for the server NOTE: You only need to do one of the above things in order for the server
to start accepting connections from the outside. to start accepting connections from the outside.
`) + "\r\n") `) + "\r\n")
@ -55,6 +55,7 @@ func ListenAndServe(
opened func(conn *Conn), opened func(conn *Conn),
closed func(conn *Conn), closed func(conn *Conn),
lnp *net.Listener, lnp *net.Listener,
http bool,
) error { ) error {
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port)) ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port))
if err != nil { if err != nil {
@ -70,7 +71,7 @@ func ListenAndServe(
log.Error(err) log.Error(err)
return err return err
} }
go handleConn(&Conn{Conn: conn}, protected, handler, opened, closed) go handleConn(&Conn{Conn: conn}, protected, handler, opened, closed, http)
} }
} }
@ -87,6 +88,7 @@ func handleConn(
handler func(conn *Conn, msg *Message, rd *AnyReaderWriter, w io.Writer, websocket bool) error, handler func(conn *Conn, msg *Message, rd *AnyReaderWriter, w io.Writer, websocket bool) error,
opened func(conn *Conn), opened func(conn *Conn),
closed func(conn *Conn), closed func(conn *Conn),
http bool,
) { ) {
opened(conn) opened(conn)
defer closed(conn) defer closed(conn)
@ -110,6 +112,14 @@ func handleConn(
rd := NewAnyReaderWriter(conn) rd := NewAnyReaderWriter(conn)
for { for {
msg, err := rd.ReadMessage() msg, err := rd.ReadMessage()
// Just closing connection if we have deprecated HTTP or WS connection,
// And --http-transport = false
if !http && (msg.ConnType == WebSocket || msg.ConnType == HTTP) {
conn.Close()
return
}
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
return return

View File

@ -51,7 +51,7 @@ func mockOpenServer() (*mockServer, error) {
s := &mockServer{port: port} s := &mockServer{port: port}
tlog.Default = tlog.New(logOutput, nil) tlog.Default = tlog.New(logOutput, nil)
go func() { go func() {
if err := controller.ListenAndServe("localhost", port, dir); err != nil { if err := controller.ListenAndServe("localhost", port, dir, true); err != nil {
log.Fatal(err) log.Fatal(err)
} }
}() }()