mirror of https://github.com/tidwall/tile38.git
Merge branch 'master' of https://github.com/tidwall/tile38
This commit is contained in:
commit
23e846e9df
|
@ -2,8 +2,9 @@
|
|||
tile38-*
|
||||
!cmd/tile38-*
|
||||
data*/
|
||||
coverage.out
|
||||
coverage.out
|
||||
packages/
|
||||
|
||||
# Ignore VS Code folder
|
||||
.vscode/
|
||||
# Ignore IDE folders
|
||||
.idea/
|
||||
.vscode/
|
||||
|
|
|
@ -32,6 +32,9 @@ var (
|
|||
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
|
||||
// for example
|
||||
// $ ./tile38-server --webhook-http-consumer-port 9999
|
||||
|
@ -106,6 +109,17 @@ func main() {
|
|||
case "--dev", "-dev":
|
||||
devMode = true
|
||||
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])
|
||||
}
|
||||
|
@ -118,6 +132,7 @@ func main() {
|
|||
flag.BoolVar(&quiet, "q", false, "Quiet logging. Totally silent.")
|
||||
flag.BoolVar(&veryVerbose, "vv", false, "Enable very verbose logging.")
|
||||
flag.Parse()
|
||||
|
||||
var logw io.Writer = os.Stderr
|
||||
if quiet {
|
||||
logw = ioutil.Discard
|
||||
|
@ -138,6 +153,11 @@ func main() {
|
|||
gitsha = ""
|
||||
}
|
||||
|
||||
httpTransportEnabled := "Enabled"
|
||||
if !httpTransport {
|
||||
httpTransportEnabled = "Disabled"
|
||||
}
|
||||
|
||||
// _____ _ _ ___ ___
|
||||
// |_ _|_| |___|_ | . |
|
||||
// | | | | | -_|_ | . |
|
||||
|
@ -148,12 +168,12 @@ func main() {
|
|||
| | |
|
||||
|____ | _ | Tile38 %s%s %d bit (%s/%s)
|
||||
| | | %sPort: %d, PID: %d
|
||||
|____ | _ |
|
||||
| | | tile38.com
|
||||
|_______|_______|
|
||||
`+"\n", core.Version, gitsha, strconv.IntSize, runtime.GOARCH, runtime.GOOS, hostd, port, os.Getpid())
|
||||
|____ | _ | HTTP & WebSocket transports: %s
|
||||
| | |
|
||||
|_______|_______| tile38.com
|
||||
`+"\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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,10 +100,10 @@ type Controller struct {
|
|||
}
|
||||
|
||||
// ListenAndServe starts a new tile38 server
|
||||
func ListenAndServe(host string, port int, dir string) error {
|
||||
return ListenAndServeEx(host, port, dir, nil)
|
||||
func ListenAndServe(host string, port int, dir string, http bool) error {
|
||||
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)
|
||||
c := &Controller{
|
||||
host: host,
|
||||
|
@ -221,7 +221,7 @@ func ListenAndServeEx(host string, port int, dir string, ln *net.Listener) error
|
|||
delete(c.conns, conn)
|
||||
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() {
|
||||
|
|
|
@ -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
|
||||
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
|
||||
following solutions:
|
||||
following solutions:
|
||||
|
||||
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
|
||||
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
|
||||
configuration file, and setting the 'protected-mode' option to 'no', and
|
||||
then restarting the server.
|
||||
3) If you started the server manually just for testing, restart it with the
|
||||
'--protected-mode no' option.
|
||||
4) Use a host address or an authentication password.
|
||||
'--protected-mode no' option.
|
||||
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.
|
||||
`) + "\r\n")
|
||||
|
||||
|
@ -55,6 +55,7 @@ func ListenAndServe(
|
|||
opened func(conn *Conn),
|
||||
closed func(conn *Conn),
|
||||
lnp *net.Listener,
|
||||
http bool,
|
||||
) error {
|
||||
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port))
|
||||
if err != nil {
|
||||
|
@ -70,7 +71,7 @@ func ListenAndServe(
|
|||
log.Error(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,
|
||||
opened func(conn *Conn),
|
||||
closed func(conn *Conn),
|
||||
http bool,
|
||||
) {
|
||||
opened(conn)
|
||||
defer closed(conn)
|
||||
|
@ -110,6 +112,14 @@ func handleConn(
|
|||
rd := NewAnyReaderWriter(conn)
|
||||
for {
|
||||
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 == io.EOF {
|
||||
return
|
||||
|
|
|
@ -51,7 +51,7 @@ func mockOpenServer() (*mockServer, error) {
|
|||
s := &mockServer{port: port}
|
||||
tlog.Default = tlog.New(logOutput, nil)
|
||||
go func() {
|
||||
if err := controller.ListenAndServe("localhost", port, dir); err != nil {
|
||||
if err := controller.ListenAndServe("localhost", port, dir, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue