diff --git a/erisdb/erisdbss/http.go b/erisdb/erisdbss/http.go index b1878657db4b54eb09be0612aeb26396e0c9a439..13573da297dcaf946e668f8919937adc455ed91d 100644 --- a/erisdb/erisdbss/http.go +++ b/erisdb/erisdbss/http.go @@ -36,12 +36,14 @@ type RequestData struct { MaxDuration uint `json:"max_duration"` } -// The response is the URL to the newly generated server. +// The response is the port of the newly generated server. The assumption +// here is that the host name or ip is the same, and the default server +// settings apply. // TODO return some "live" data after starting the node, so that // the requester can validate that everything is fine. Maybe // some data directly from the state manager. Genesis hash? type ResponseData struct { - URL string `json:"URL"` + Port string `json:"port"` } // Serves requests to fire up erisdb executables. POSTing to the server @@ -104,7 +106,7 @@ func (this *ServerServer) handleFunc(c *gin.Context) { http.Error(c.Writer, "Internal error: "+errA.Error(), 500) return } - log.Debug("Work done.", "URL", resp.URL) + log.Debug("Work done.", "PORT", resp.Port) w := c.Writer enc := json.NewEncoder(w) enc.Encode(resp) diff --git a/erisdb/erisdbss/server_manager.go b/erisdb/erisdbss/server_manager.go index f8b0344f8a81df2faa4576427ab18b40f3157355..b3a617b5968256965bdacc4bff958c6199ceee8b 100644 --- a/erisdb/erisdbss/server_manager.go +++ b/erisdb/erisdbss/server_manager.go @@ -183,14 +183,12 @@ func (this *ServerManager) add(data *RequestData) (*ResponseData, error) { } st := newServeTask(port, workDir, maxDur, proc) - this.running = append(this.running, st) - - URL := fmt.Sprintf("http://%s:%d", config.Bind.Address, port) + this.running = append(this.running, st) // TODO add validation data. The node should ideally return some post-deploy state data // and send it back with the server URL, so that the validity of the chain can be // established client-side before starting the tests. - return &ResponseData{URL: URL}, nil + return &ResponseData{fmt.Sprintf("%d",port)}, nil } // Add a new erisdb process to the list. diff --git a/server/config.go b/server/config.go index 0fa49d6a8a58ab0ea1d8a6126578268fc7e2db26..9d979f06b4747ba0ff09ed389c4c608d3ea4dc79 100644 --- a/server/config.go +++ b/server/config.go @@ -59,7 +59,7 @@ func DefaultServerConfig() *ServerConfig { kp := "" return &ServerConfig{ Bind: Bind{ - Address: "0.0.0.0", + Address: "", Port: 1337, }, TLS: TLS{TLS: false, diff --git a/server/server.go b/server/server.go index 95ad7790451c105d2f19deac41b961c3ba3a5a2d..d2532cd3b066c0f051819dde3b670d0bb27a926a 100644 --- a/server/server.go +++ b/server/server.go @@ -54,12 +54,12 @@ func (this *ServeProcess) Start() error { InitLogger(config) - if config.CORS.Enable { + // if config.CORS.Enable { ch := NewCORSMiddleware(config.CORS) router.Use(gin.Recovery(), logHandler, ch) - } else { - router.Use(gin.Recovery(), logHandler) - } + //} else { + // router.Use(gin.Recovery(), logHandler) + //} address := config.Bind.Address port := config.Bind.Port diff --git a/server/websocket.go b/server/websocket.go index 732b45aaa92ca40176c07aa0f39b9166a8b4ce78..2481fb570ae940516ba4613da7b1fd0392d8e745 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -70,7 +70,7 @@ func (this *WebSocketServer) Start(config *ServerConfig, router *gin.Engine) { // TODO Will this be enough for massive "get blockchain" requests? WriteBufferSize: 1024, } - this.upgrader.CheckOrigin = nil + this.upgrader.CheckOrigin = func(r *http.Request) bool {return true} router.GET(config.WebSocket.WebSocketEndpoint, this.handleFunc) this.running = true diff --git a/test/mock/mock_web_api_test.go b/test/mock/mock_web_api_test.go index 7e07c745bf579c0782aed4283f5f96688ac434d4..456d628342587cd4640aa6f9adfa44764e81590d 100644 --- a/test/mock/mock_web_api_test.go +++ b/test/mock/mock_web_api_test.go @@ -18,7 +18,6 @@ import ( "testing" "os" "runtime" - "time" ) func init() { @@ -49,7 +48,7 @@ func (this *MockSuite) SetupSuite() { // The server restServer := edb.NewRestServer(codec, pipe, evtSubs) sConf := server.DefaultServerConfig() - sConf.Bind.Port = 31473 + sConf.Bind.Port = 31402 // Create a server process. proc := server.NewServeProcess(sConf, restServer) err := proc.Start() @@ -59,16 +58,13 @@ func (this *MockSuite) SetupSuite() { this.serveProcess = proc this.codec = edb.NewTCodec() this.testData = testData - this.sUrl = "http://localhost:31473" + this.sUrl = "http://localhost:31402" } func (this *MockSuite) TearDownSuite() { sec := this.serveProcess.StopEventChannel() this.serveProcess.Stop(0) <-sec - // Tests are done rapidly, this is just to give that extra milliseconds - // to shut down the previous server (may be excessive). - time.Sleep(500*time.Millisecond) } // ********************************************* Consensus ********************************************* diff --git a/test/server/http_burst_test.go b/test/server/http_burst_test.go index f74bbb2cc6fff5f31b5e76fc3521f2f90b5f5220..2ac5dbcc09a8201c2bde87e2f2114587205408ff 100644 --- a/test/server/http_burst_test.go +++ b/test/server/http_burst_test.go @@ -32,7 +32,7 @@ func TestHttpFlooding(t *testing.T) { func runHttp() error { c := 0 for c < HTTP_MESSAGES { - resp, errG := http.Get("http://localhost:31333/scumbag") + resp, errG := http.Get("http://localhost:31400/scumbag") if errG != nil { return errG } diff --git a/test/server/scumbag.go b/test/server/scumbag.go index bc43809271ef4d3b11c158ca1284e29f313a0daf..fb01e75d315164a5499a8705296e1729cf521048 100644 --- a/test/server/scumbag.go +++ b/test/server/scumbag.go @@ -57,13 +57,13 @@ func NewScumsocketServer(maxConnections uint) *server.WebSocketServer { func NewServeScumbag() *server.ServeProcess { cfg := server.DefaultServerConfig() - cfg.Bind.Port = uint16(31333) + cfg.Bind.Port = uint16(31400) return server.NewServeProcess(cfg, NewScumbagServer()) } func NewServeScumSocket(wsServer *server.WebSocketServer) *server.ServeProcess { cfg := server.DefaultServerConfig() cfg.WebSocket.WebSocketEndpoint = "/scumsocket" - cfg.Bind.Port = uint16(31337) + cfg.Bind.Port = uint16(31401) return server.NewServeProcess(cfg, wsServer) } diff --git a/test/server/ws_burst_test.go b/test/server/ws_burst_test.go index 67212437029af21491ac9386e630b07d4a60ae2e..e3922d98dd682072db4dd0c93f8beb7a1b77adab 100644 --- a/test/server/ws_burst_test.go +++ b/test/server/ws_burst_test.go @@ -89,7 +89,7 @@ func runWs() error { } func wsClient(doneChan chan bool, errChan chan error) { - client := client.NewWSClient("ws://localhost:31337/scumsocket") + client := client.NewWSClient("ws://localhost:31401/scumsocket") _, err := client.Dial() if err != nil { errChan <- err diff --git a/test/web_api/query_test.go b/test/web_api/query_test.go index d0f5f7016094f4a0d98adf155ad77374e71f0040..e6714d1751e7139731832158410fc3d258f6fed1 100644 --- a/test/web_api/query_test.go +++ b/test/web_api/query_test.go @@ -15,9 +15,10 @@ import ( "os" "path" "testing" - "time" ) +const QS_URL = "http://localhost:31403/server" + type QuerySuite struct { suite.Suite baseDir string @@ -30,7 +31,9 @@ type QuerySuite struct { func (this *QuerySuite) SetupSuite() { baseDir := path.Join(os.TempDir(), "/.edbservers") ss := ess.NewServerServer(baseDir) - proc := server.NewServeProcess(nil, ss) + cfg := server.DefaultServerConfig() + cfg.Bind.Port = uint16(31403) + proc := server.NewServeProcess(cfg, ss) err := proc.Start() if err != nil { panic(err) @@ -41,14 +44,15 @@ func (this *QuerySuite) SetupSuite() { requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} rBts, _ := this.codec.EncodeBytes(requestData) - resp, _ := http.Post(SS_URL, "application/json", bytes.NewBuffer(rBts)) + resp, _ := http.Post(QS_URL, "application/json", bytes.NewBuffer(rBts)) rd := &ess.ResponseData{} err2 := this.codec.Decode(rd, resp.Body) if err2 != nil { panic(err2) } - fmt.Println("Received URL: " + rd.URL) - this.sUrl = rd.URL + fmt.Println("Received Port: " + rd.Port) + this.sUrl = "http://localhost:" + rd.Port + fmt.Println("URL: " + this.sUrl) this.testData = testData } @@ -56,9 +60,6 @@ func (this *QuerySuite) TearDownSuite() { sec := this.serveProcess.StopEventChannel() this.serveProcess.Stop(0) <-sec - // Tests are done rapidly, this is just to give that extra milliseconds - // to shut down the previous server (may be excessive). - time.Sleep(500*time.Millisecond) } // ********************************************* Tests ********************************************* diff --git a/test/web_api/shared.go b/test/web_api/shared.go index 9c1ad6f31802e92c144f1c55cb65a31a23de827b..46962a317725043a2726f8237933ce689883bc6f 100644 --- a/test/web_api/shared.go +++ b/test/web_api/shared.go @@ -7,7 +7,6 @@ import ( "runtime" ) -const SS_URL = "http://localhost:1337/server" const SERVER_DURATION = 10 func init() { diff --git a/test/web_api/web_api_test.go b/test/web_api/web_api_test.go index c453fd7707aa384c0f95d6286d6f7adaacaff76a..bc765df0ca5908cdaa2d0cf8a2207ee43023e888 100644 --- a/test/web_api/web_api_test.go +++ b/test/web_api/web_api_test.go @@ -18,9 +18,10 @@ import ( "os" "path" "testing" - "time" ) +const WAPIS_URL = "http://localhost:31404/server" + type WebApiSuite struct { suite.Suite baseDir string @@ -34,7 +35,9 @@ func (this *WebApiSuite) SetupSuite() { gin.SetMode(gin.ReleaseMode) baseDir := path.Join(os.TempDir(), "/.edbservers") ss := ess.NewServerServer(baseDir) - proc := server.NewServeProcess(nil, ss) + cfg := server.DefaultServerConfig() + cfg.Bind.Port = uint16(31404) + proc := server.NewServeProcess(cfg, ss) err := proc.Start() if err != nil { panic(err) @@ -45,14 +48,14 @@ func (this *WebApiSuite) SetupSuite() { requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} rBts, _ := this.codec.EncodeBytes(requestData) - resp, _ := http.Post(SS_URL, "application/json", bytes.NewBuffer(rBts)) + resp, _ := http.Post(WAPIS_URL, "application/json", bytes.NewBuffer(rBts)) rd := &ess.ResponseData{} err2 := this.codec.Decode(rd, resp.Body) if err2 != nil { panic(err2) } - fmt.Println("Received URL: " + rd.URL) - this.sUrl = rd.URL + fmt.Println("Received Port: " + rd.Port) + this.sUrl = "http://localhost:" + rd.Port this.testData = testData } @@ -60,9 +63,6 @@ func (this *WebApiSuite) TearDownSuite() { sec := this.serveProcess.StopEventChannel() this.serveProcess.Stop(0) <-sec - // Tests are done rapidly, this is just to give that extra milliseconds - // to shut down the previous server (may be excessive). - time.Sleep(500*time.Millisecond) } // ********************************************* Consensus *********************************************