From 3c30805b66e6d8c584ee613561cf08b1c6802388 Mon Sep 17 00:00:00 2001
From: Androlo <andreas@erisindustries.com>
Date: Tue, 9 Jun 2015 21:20:40 +0200
Subject: [PATCH] Config stuff.

---
 cmd/erisdb/main.go                            |   1 +
 cmd/erisdbmock/main.go                        |  27 ----
 erisdb/erisdbss/http.go                       |   9 +-
 erisdb/json_service.go                        |   2 +-
 erisdb/pipe/accounts.go                       |   4 +-
 erisdb/pipe/types.go                          |   2 +-
 erisdb/serve.go                               |   2 +-
 files/files.go                                |  77 +++++++++--
 files/files_test.go                           |  33 ++++-
 files/log.go                                  |   7 +
 server/config.go                              | 120 ++++++++++++------
 server/logging.go                             |  56 ++++++++
 server/server.go                              |  34 +++--
 server/websocket.go                           |  39 +-----
 test/scumbag.go                               |   4 +-
 .../{mock_pipe_test.go => mock_pipe_tes.go}   |  14 +-
 16 files changed, 282 insertions(+), 149 deletions(-)
 delete mode 100644 cmd/erisdbmock/main.go
 create mode 100644 files/log.go
 create mode 100644 server/logging.go
 rename test/temp/{mock_pipe_test.go => mock_pipe_tes.go} (83%)

diff --git a/cmd/erisdb/main.go b/cmd/erisdb/main.go
index d567cc54..1b4afa6f 100644
--- a/cmd/erisdb/main.go
+++ b/cmd/erisdb/main.go
@@ -23,6 +23,7 @@ func main() {
 	if errSe != nil {
 		panic(errSe.Error())
 	}
+	// TODO For now.
 	fmt.Println("DONTMINDME55891")
 	<- proc.StopEventChannel()
 }
diff --git a/cmd/erisdbmock/main.go b/cmd/erisdbmock/main.go
deleted file mode 100644
index b24d9071..00000000
--- a/cmd/erisdbmock/main.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// Starts a server using a mock pipe for manual testing.
-package main
-
-import (
-	"github.com/eris-ltd/erisdb/server"
-	edb "github.com/eris-ltd/erisdb/erisdb"
-	"github.com/eris-ltd/erisdb/test/mock"
-)
-
-func main() {
-	mockData := mock.NewDefaultMockData()
-	mockPipe := mock.NewMockPipe(mockData)
-	codec := &edb.TCodec{}
-	tmwss := edb.NewErisDbWsService(codec, mockPipe)
-	tmjs := edb.NewErisDbJsonService(codec, mockPipe, nil)
-	
-	// The servers.
-	jsonServer := edb.NewJsonRpcServer(tmjs)
-	restServer := edb.NewRestServer(codec, mockPipe, nil)
-	wsServer := server.NewWebSocketServer(100, tmwss)
-	proc := server.NewServeProcess(nil, jsonServer, restServer, wsServer)
-	err := proc.Start()
-	if err != nil {
-		panic(err.Error())
-	}
-	<- proc.StopEventChannel()
-}
\ No newline at end of file
diff --git a/erisdb/erisdbss/http.go b/erisdb/erisdbss/http.go
index 9e7e3e50..cfd1d803 100644
--- a/erisdb/erisdbss/http.go
+++ b/erisdb/erisdbss/http.go
@@ -35,7 +35,7 @@ moniker = "anothertester"
 seeds = ""
 fast_sync = false
 db_backend = "leveldb"
-log_level = "debug"
+log_level = "warn"
 node_laddr = ""
 `
 
@@ -200,7 +200,7 @@ func (this *ServerManager) add(data *RequestData) (*ResponseData, error) {
 	config := server.DefaultServerConfig()
 	// Port is PORT_BASE + a value between 1 and the max number of servers.
 	port := uint16(PORT_BASE + this.idPool.GetId())
-	config.Port = port
+	config.Bind.Port = port
 
 	folderName := fmt.Sprintf("testnode%d", port)
 	workDir, errCWD := this.createWorkDir(data, config, folderName)
@@ -227,8 +227,7 @@ func (this *ServerManager) add(data *RequestData) (*ResponseData, error) {
 	
 	for scanner.Scan() {
 		text := scanner.Text()
-		fmt.Println(text)
-		if strings.Index(text, "DONTMINDME55891") == -1 {
+		if strings.Index(text, "DONTMINDME55891") != -1 {
 			break
 		}
 	}
@@ -245,7 +244,7 @@ func (this *ServerManager) add(data *RequestData) (*ResponseData, error) {
 	st := newServeTask(port, workDir, maxDur, proc)
 	this.running = append(this.running, st)
 
-	URL := "http://" + config.Address + ":" + fmt.Sprintf("%d", port) + config.JsonRpcPath
+	URL := "http://" + config.Bind.Address + ":" + fmt.Sprintf("%d", port) + config.HTTP.JsonRpcPath
 
 	// 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
diff --git a/erisdb/json_service.go b/erisdb/json_service.go
index eddb7812..5887b065 100644
--- a/erisdb/json_service.go
+++ b/erisdb/json_service.go
@@ -23,7 +23,7 @@ func NewJsonRpcServer(service server.HttpService) *JsonRpcServer {
 
 // Start adds the rpc path to the router.
 func (this *JsonRpcServer) Start(config *server.ServerConfig, router *gin.Engine) {
-	router.POST(config.JsonRpcPath, this.handleFunc)
+	router.POST(config.HTTP.JsonRpcPath, this.handleFunc)
 	this.running = true
 }
 
diff --git a/erisdb/pipe/accounts.go b/erisdb/pipe/accounts.go
index 01a67293..7bf264ec 100644
--- a/erisdb/pipe/accounts.go
+++ b/erisdb/pipe/accounts.go
@@ -107,7 +107,7 @@ func (this *accounts) Storage(address []byte) (*Storage, error) {
 
 	state := this.consensusState.GetState()
 	account := state.GetAccount(address)
-	storageItems := make([]*StorageItem, 0)
+	storageItems := make([]StorageItem, 0)
 	if account == nil {
 		return &Storage{nil, storageItems}, nil
 	}
@@ -115,7 +115,7 @@ func (this *accounts) Storage(address []byte) (*Storage, error) {
 	storageTree := state.LoadStorage(storageRoot)
 
 	storageTree.Iterate(func(key interface{}, value interface{}) bool {
-		storageItems = append(storageItems, &StorageItem{
+		storageItems = append(storageItems, StorageItem{
 			key.([]byte), value.([]byte)})
 		return false
 	})
diff --git a/erisdb/pipe/types.go b/erisdb/pipe/types.go
index b9819cd2..31f84c7e 100644
--- a/erisdb/pipe/types.go
+++ b/erisdb/pipe/types.go
@@ -45,7 +45,7 @@ type (
 	// Account storage
 	Storage struct {
 		StorageRoot  []byte         `json:"storage_root"`
-		StorageItems []*StorageItem `json:"storage_items"`
+		StorageItems []StorageItem `json:"storage_items"`
 	}
 
 	// *********************************** Blockchain ***********************************
diff --git a/erisdb/serve.go b/erisdb/serve.go
index 7d0775d2..77df2dfd 100644
--- a/erisdb/serve.go
+++ b/erisdb/serve.go
@@ -66,7 +66,7 @@ func ServeErisDB(workDir string) (*server.ServeProcess, error) {
 	// The servers.
 	jsonServer := NewJsonRpcServer(tmjs)
 	restServer := NewRestServer(codec, pipe, evtSubs)
-	wsServer := server.NewWebSocketServer(sConf.MaxWebSocketSessions, tmwss)
+	wsServer := server.NewWebSocketServer(sConf.WebSocket.MaxWebSocketSessions, tmwss)
 	// Create a server process.
 	proc := server.NewServeProcess(sConf, jsonServer, restServer, wsServer)
 	
diff --git a/files/files.go b/files/files.go
index c30c4725..eaa2b3ba 100644
--- a/files/files.go
+++ b/files/files.go
@@ -1,4 +1,4 @@
-
+// Cross-platform file utils.
 package files
 
 import (
@@ -11,30 +11,32 @@ import (
 // We don't concern ourselves with executable files here.
 const (
 	FILE_RW = os.FileMode(0666)
-	FILE_W = os.FileMode(0x222) 
-	FILE_R = os.FileMode(0444)
+	FILE_W  = os.FileMode(0222)
+	FILE_R  = os.FileMode(0444)
 )
 
-func isWritable(fm os.FileMode) bool {
-	return fm & 2 == 2
+func IsWritable(fm os.FileMode) bool {
+	return fm&2 == 2
 }
 
+// Write a file that has both read and write flags set.
 func WriteFileRW(fileName string, data []byte) error {
 	return WriteFile(fileName, data, FILE_RW)
 }
 
+// Write file with the read-only flag set.
 func WriteFileReadOnly(fileName string, data []byte) error {
 	return WriteFile(fileName, data, FILE_R)
 }
 
+// Write file with the write-only flag set.
 func WriteFileWriteOnly(fileName string, data []byte) error {
 	return WriteFile(fileName, data, FILE_W)
 }
 
-// WriteFile. Will do a 
-func WriteFile(filename string, data []byte, perm os.FileMode) error {
-	f, err := os.Create(filename)
-	
+// WriteFile.
+func WriteFile(fileName string, data []byte, perm os.FileMode) error {
+	f, err := os.Create(fileName)
 	if err != nil {
 		fmt.Println("ERROR OPENING: " + err.Error())
 		return err
@@ -49,10 +51,63 @@ func WriteFile(filename string, data []byte, perm os.FileMode) error {
 		err2 = io.ErrShortWrite
 		return err
 	}
-	
+
 	return nil
 }
 
+// Does the file with the given name exist?
+func FileExists(fileName string) bool {
+	_, err := os.Stat(fileName)
+	return !os.IsNotExist(err)
+}
+
+func IsRegular(fileName string) bool {
+	fs, err := os.Stat(fileName)
+	if err != nil {
+		return false
+	}
+	return fs.Mode().IsRegular()
+}
+
+func WriteAndBackup(fileName string, data []byte) error {
+	fs, err := os.Stat(fileName)
+	if err != nil {
+		return err
+	}
+	if !fs.Mode().IsRegular() {
+		return fmt.Errorf("Not a regular file: " + fileName)
+	}
+	backupName := fileName + ".bak"
+	fs, err = os.Stat(backupName)
+	if err != nil {
+		if !os.IsNotExist(err) {
+			return err
+		}
+	} else {
+		// We only work with regular files.
+		if !fs.Mode().IsRegular() {
+			return fmt.Errorf(backupName + " is not a regular file.")
+		}
+		errR := os.Remove(backupName)
+		if errR != nil {
+			return errR
+		}
+	}
+	// Backup file should now be gone.
+	// Read from original file.
+	bts, errR := ReadFile(fileName)
+	if errR != nil {
+		return errR
+	}
+	// Write it to the backup.
+	errW := WriteFileRW(backupName, bts)
+	if errW != nil {
+		return errW
+	}
+	// Write new bytes to original.
+	return WriteFileRW(fileName, data)
+}
+
 func ReadFile(fileName string) ([]byte, error) {
 	return ioutil.ReadFile(fileName)
-}
\ No newline at end of file
+}
diff --git a/files/files_test.go b/files/files_test.go
index 124b9fe0..8d612174 100644
--- a/files/files_test.go
+++ b/files/files_test.go
@@ -9,17 +9,18 @@ import (
 )
 
 var tempFolder = os.TempDir()
-var fileData = []byte("aaaaaaaaaaaaaaaaa")
+var fileData = []byte("aaaaaaaaaaaabbbbbbbbbbbbbbbbbbbaeeeeeeeeeeeeeeaaaaaa")
+var fileData2 = []byte("bbbbbbbbbbbb66666666666666666666664bb")
 
 func TestWriteRemove(t *testing.T) {
 	fileName := "testfile"
-	write(t, fileName)
+	write(t, fileName, fileData)
 	remove(t, fileName)
 }
 
 func TestWriteReadRemove(t *testing.T) {
 	fileName := "testfile"
-	write(t, fileName)
+	write(t, fileName, fileData)
 	readAndCheck(t, fileName, fileData)
 	remove(t, fileName)
 }
@@ -27,28 +28,46 @@ func TestWriteReadRemove(t *testing.T) {
 func TestRenameRemove(t *testing.T) {
 	fileName0 := "file0"
 	fileName1 := "file1"
-	write(t, fileName0)
+	write(t, fileName0, fileData)
 	rename(t, fileName0, fileName1)
 	readAndCheck(t, fileName1, fileData)
 	remove(t, fileName1)
 	checkGone(t, fileName0)
 }
 
+func TestWriteAndBackup(t *testing.T) {
+	fileName := "testfile"
+	backupName := "testfile.bak"
+	if FileExists(fileName) {
+		remove(t, fileName)
+	}
+	if FileExists(backupName) {
+		remove(t, backupName)
+	}
+	write(t, fileName, fileData)
+	readAndCheck(t, fileName, fileData)
+	WriteAndBackup(getName(fileName), fileData2)
+	readAndCheck(t, backupName, fileData)
+	remove(t, fileName)
+	remove(t, backupName)
+	checkGone(t, fileName)
+}
+
 // Helpers
 
 func getName(name string) string {
 	return path.Join(tempFolder, name)
 }
 
-func write(t *testing.T, fileName string) {
-	err := WriteFile(getName(fileName), fileData, FILE_RW)
+func write(t *testing.T, fileName string, data []byte) {
+	err := WriteFile(getName(fileName), data, FILE_RW)
 	assert.NoError(t, err)
 }
 
 func readAndCheck(t *testing.T, fileName string, btsIn []byte) {
 	bts, err := ReadFile(getName(fileName))
 	assert.NoError(t, err)
-	assert.True(t, bytes.Equal(bts,btsIn), "Failed to read file data. Written: %s, Read: %s\n", string(fileData), string(bts))
+	assert.True(t, bytes.Equal(bts, btsIn), "Failed to read file data. Written: %s, Read: %s\n", string(fileData), string(bts))
 }
 
 func remove(t *testing.T, fileName string) {
diff --git a/files/log.go b/files/log.go
new file mode 100644
index 00000000..153aa9cb
--- /dev/null
+++ b/files/log.go
@@ -0,0 +1,7 @@
+package files
+
+import (
+	"github.com/tendermint/log15"
+)
+
+var log = log15.New("module", "eris/server/files")
\ No newline at end of file
diff --git a/server/config.go b/server/config.go
index 0f23339e..1eb9b3da 100644
--- a/server/config.go
+++ b/server/config.go
@@ -2,63 +2,105 @@ package server
 
 import (
 	"github.com/eris-ltd/erisdb/files"
-	"github.com/BurntSushi/toml"
-	"bytes"
-	"os"
-	"path"
+	"github.com/naoina/toml"
 )
 
-// TODO fix his before monday (june 8th).
-
 // Standard configuration file for the server.
-type ServerConfig struct {
-	Address              string   `json:"address"`
-	Port                 uint16   `json:"port"`
-	CheckOrigin          bool     `json:"check_origin"`
-	AllowedOrigins       []string `json:"allow_origins"`
-	TLS                  bool     `json:"tls"`
-	CertPath             string   `json:"cert_path"`
-	KeyPath              string   `json:"key_path"`
-	WebSocketPath        string   `json:"websocket_path"`
-	JsonRpcPath          string   `json:"json_rpc_path"`
-	MaxWebSocketSessions uint     `json:"max_websocket_sessions"`
-}
+type (
+	ServerConfig struct {
+		Bind      Bind      `toml:"bind"`
+		TLS       TLS       `toml:"TLS"`
+		//CORS      *CORS      `toml:"CORS"`
+		HTTP      HTTP      `toml:"HTTP"`
+		WebSocket WebSocket `toml:"web_socket"`
+		Logging   Logging   `toml:"logging"`
+	}
+
+	Bind struct {
+		Address string `toml:"address"`
+		Port    uint16 `toml:"port"`
+	}
+
+	TLS struct {
+		TLS      bool   `toml:"tls"`
+		CertPath string `toml:"cert_path"`
+		KeyPath  string `toml:"key_path"`
+	}
+
+	// Options stores configurations
+	CORS struct {
+		AllowOrigins     []string `toml:"allow_origins"`
+		AllowCredentials bool     `toml:"allow_credentials"`
+		AllowMethods     []string `toml:"allow_methods"`
+		AllowHeaders     []string `toml:"allow_headers"`
+		ExposeHeaders    []string `toml:"expose_headers"`
+		MaxAge           uint64   `toml:"max_age"`
+	}
+
+	HTTP struct {
+		JsonRpcPath string `toml:"json_rpc_path"`
+	}
+
+	WebSocket struct {
+		WebSocketPath        string `toml:"websocket_path"`
+		MaxWebSocketSessions uint   `toml:"max_websocket_sessions"`
+	}
+
+	Logging struct {
+		ConsoleLogLevel string `toml:"console_log_level"`
+		FileLogLevel    string `toml:"file_log_level"`
+		LogFile         string `toml:"log_level"`
+	}
+)
 
 func DefaultServerConfig() *ServerConfig {
-	pwd, _ := os.Getwd()
-	cp := path.Join(pwd, "cert.pem")
-	kp := path.Join(pwd, "key.pem")
+	cp := ""
+	kp := ""
 	return &ServerConfig{
-		Address:              "0.0.0.0",
-		Port:                 1337,
-		CheckOrigin:          false,
-		AllowedOrigins:       []string{"*"},
-		TLS:                  false,
-		CertPath:             cp,
-		KeyPath:              kp,
-		WebSocketPath:        "/socketrpc",
-		JsonRpcPath:          "/rpc",
-		MaxWebSocketSessions: 50,
+		Bind: Bind{
+			Address: "0.0.0.0",
+			Port:    1337,
+		},
+		TLS: TLS{TLS: false,
+			CertPath: cp,
+			KeyPath:  kp,
+		},
+		/*
+			CORS: CORS{
+				},*/
+		HTTP: HTTP{JsonRpcPath: "/rpc"},
+		WebSocket: WebSocket{
+			WebSocketPath:        "/socketrpc",
+			MaxWebSocketSessions: 50,
+		},
+		Logging: Logging{
+			ConsoleLogLevel: "error",
+			FileLogLevel:    "error",
+			LogFile:         "",
+		},
 	}
 }
 
 // Read a TOML server configuration file.
 func ReadServerConfig(filePath string) (*ServerConfig, error) {
+	bts, err := files.ReadFile(filePath)
+	if err != nil {
+		return nil, err
+	}
 	cfg := &ServerConfig{}
-	_, errD := toml.DecodeFile(filePath, cfg)
-	if errD != nil {
-		return nil, errD
+	err2 := toml.Unmarshal(bts, cfg)
+	if err2 != nil {
+		return nil, err2
 	}
 	return cfg, nil
 }
 
-// We want to do this with the files package methods, so writing to a byte buffer. 
+// Write a server configuration file.
+// TODO use the backup file write.
 func WriteServerConfig(filePath string, cfg *ServerConfig) error {
-	var buf bytes.Buffer
-	enc := toml.NewEncoder(&buf)
-	err := enc.Encode(cfg)
+	bts, err := toml.Marshal(*cfg)
 	if err != nil {
 		return err
 	}
-	return files.WriteFileRW(filePath, buf.Bytes())
+	return files.WriteFileRW(filePath, bts)
 }
diff --git a/server/logging.go b/server/logging.go
new file mode 100644
index 00000000..a806a5a3
--- /dev/null
+++ b/server/logging.go
@@ -0,0 +1,56 @@
+package server
+
+import (
+	"fmt"
+	"github.com/tendermint/log15"
+	"os"
+)
+
+var rootHandler log15.Handler
+
+func Init(config *ServerConfig) {
+
+	consoleLogLevel := config.Logging.ConsoleLogLevel
+
+	// stdout handler
+	handlers := []log15.Handler{}
+	stdoutHandler := log15.LvlFilterHandler(
+		getLevel(consoleLogLevel),
+		log15.StreamHandler(os.Stdout, log15.TerminalFormat()),
+	)
+	handlers = append(handlers, stdoutHandler)
+
+	if config.Logging.LogFile != "" {
+		fileLogLevel := config.Logging.FileLogLevel
+		fh, err := log15.FileHandler(config.Logging.LogFile, log15.LogfmtFormat())
+		if err != nil {
+			fmt.Println("Error creating log file: " + err.Error())
+			os.Exit(1)
+		}
+		fileHandler := log15.LvlFilterHandler(getLevel(fileLogLevel), fh)
+		handlers = append(handlers, fileHandler)
+	}
+	
+	rootHandler = log15.MultiHandler(handlers...)
+
+	// By setting handlers on the root, we handle events from all loggers.
+	log15.Root().SetHandler(rootHandler)
+}
+
+// See binary/log for an example of usage.
+func RootHandler() log15.Handler {
+	return rootHandler
+}
+
+func New(ctx ...interface{}) log15.Logger {
+	return log15.Root().New(ctx...)
+}
+
+func getLevel(lvlString string) log15.Lvl {
+	lvl, err := log15.LvlFromString(lvlString)
+	if err != nil {
+		fmt.Printf("Invalid log level %v: %v", lvlString, err)
+		os.Exit(1)
+	}
+	return lvl
+}
diff --git a/server/server.go b/server/server.go
index dbdb70dd..b67a250a 100644
--- a/server/server.go
+++ b/server/server.go
@@ -4,6 +4,7 @@ import (
 	"crypto/tls"
 	"fmt"
 	"github.com/gin-gonic/gin"
+	// cors "github.com/tommy351/gin-cors"
 	"gopkg.in/tylerb/graceful.v1"
 	"net"
 	"net/http"
@@ -49,12 +50,14 @@ func (this *ServeProcess) Start() error {
 
 	router := gin.New()
 
-	router.Use(gin.Recovery(), logHandler)
-	
 	config := this.config
 
-	address := config.Address
-	port := config.Port
+	// ch := NewCORSMiddleware(config.CORS)
+	// router.Use(gin.Recovery(), logHandler, ch)
+	router.Use(gin.Recovery(), logHandler)
+
+	address := config.Bind.Address
+	port := config.Bind.Port
 
 	if port == 0 {
 		return fmt.Errorf("0 is not a valid port.")
@@ -80,7 +83,7 @@ func (this *ServeProcess) Start() error {
 	}
 
 	// For secure connections.
-	if config.TLS {
+	if config.TLS.TLS {
 		addr := srv.Addr
 		if addr == "" {
 			addr = ":https"
@@ -93,7 +96,7 @@ func (this *ServeProcess) Start() error {
 
 		var tErr error
 		tConfig.Certificates = make([]tls.Certificate, 1)
-		tConfig.Certificates[0], tErr = tls.LoadX509KeyPair(config.CertPath, config.KeyPath)
+		tConfig.Certificates[0], tErr = tls.LoadX509KeyPair(config.TLS.CertPath, config.TLS.KeyPath)
 		if tErr != nil {
 			return tErr
 		}
@@ -163,8 +166,8 @@ func (this *ServeProcess) StartEventChannel() <-chan struct{} {
 // Get a stop-event channel from the server. The event happens
 // after the Stop() function has been called, and after the
 // timeout has passed. When the timeout has passed it will wait
-// for confirmation from the http.Server, which normally takes 
-// a very short time (milliseconds). 
+// for confirmation from the http.Server, which normally takes
+// a very short time (milliseconds).
 func (this *ServeProcess) StopEventChannel() <-chan struct{} {
 	lChan := make(chan struct{}, 1)
 	this.stopListenChans = append(this.stopListenChans, lChan)
@@ -187,7 +190,7 @@ func NewServeProcess(config *ServerConfig, servers ...Server) *ServeProcess {
 	return sp
 }
 
-// Used to enable log15 logging instead of the default Gin logging. 
+// Used to enable log15 logging instead of the default Gin logging.
 // This is done mainly because we at Eris uses log15 in other components.
 // TODO make this optional perhaps.
 func logHandler(c *gin.Context) {
@@ -205,3 +208,16 @@ func logHandler(c *gin.Context) {
 	log.Info("[GIN] HTTP: "+clientIP, "Code", statusCode, "Method", method, "path", path, "error", comment)
 
 }
+/*
+func NewCORSMiddleware(options CORS) gin.HandlerFunc {
+	o := cors.Options{
+		AllowCredentials: options.AllowCredentials,
+		AllowHeaders:     options.AllowHeaders,
+		AllowMethods:     options.AllowMethods,
+		AllowOrigins:     options.AllowOrigins,
+		ExposeHeaders:    options.ExposeHeaders,
+		MaxAge:           time.Duration(options.MaxAge),
+	}
+	return cors.Middleware(o)
+}
+*/
\ No newline at end of file
diff --git a/server/websocket.go b/server/websocket.go
index 8f294d88..fc673ab4 100644
--- a/server/websocket.go
+++ b/server/websocket.go
@@ -64,50 +64,15 @@ func NewWebSocketServer(maxSessions uint, service WebSocketService) *WebSocketSe
 func (this *WebSocketServer) Start(config *ServerConfig, router *gin.Engine) {
 
 	this.config = config
-	if config.CheckOrigin {
-		for _, origin := range config.AllowedOrigins {
-			if origin == "*" {
-				this.allOrigins = true
-				break
-			}
-		}
-	}
 
 	this.upgrader = websocket.Upgrader{
 		ReadBufferSize: 1024,
 		// TODO Will this be enough for massive "get blockchain" requests?
 		WriteBufferSize: 1024,
 	}
-	// If no origin check is to be made, we set the upgrader function to nil as per
-	// the instructions.
-	if !this.config.CheckOrigin {
-		this.upgrader.CheckOrigin = nil
-	} else {
-		// TODO 
-		this.upgrader.CheckOrigin = func(r *http.Request) bool {
-			// Get the origin as an array.
-			origin := r.Header["Origin"]
-			// If no origin is provided - disallow.
-			if len(origin) == 0 {
-				return false
-			}
-			o := origin[0]
-			// If all origins is allowed.
-			if this.allOrigins {
-				return true
-			}
-			// Iterate over all allowed origins and look for a match.
-			for _, origin := range this.config.AllowedOrigins {
-				if o == origin {
-					return true
-				}
-			}
-			// If the matching failed - disallow.
-			return false
-		}
-	}
+	this.upgrader.CheckOrigin = nil
 
-	router.GET(config.WebSocketPath, this.handleFunc)
+	router.GET(config.WebSocket.WebSocketPath, this.handleFunc)
 	this.running = true
 }
 
diff --git a/test/scumbag.go b/test/scumbag.go
index 41ce40b4..40b414d1 100644
--- a/test/scumbag.go
+++ b/test/scumbag.go
@@ -61,7 +61,7 @@ func NewServeScumbag() *server.ServeProcess {
 
 func NewServeScumSocket(wsServer *server.WebSocketServer) *server.ServeProcess{
 	cfg := server.DefaultServerConfig()
-	cfg.WebSocketPath = "/scumsocket"
-	cfg.Port = uint16(31337)
+	cfg.WebSocket.WebSocketPath = "/scumsocket"
+	cfg.Bind.Port = uint16(31337)
 	return server.NewServeProcess(cfg, wsServer)	
 }
\ No newline at end of file
diff --git a/test/temp/mock_pipe_test.go b/test/temp/mock_pipe_tes.go
similarity index 83%
rename from test/temp/mock_pipe_test.go
rename to test/temp/mock_pipe_tes.go
index fa8458ad..fa1e3316 100644
--- a/test/temp/mock_pipe_test.go
+++ b/test/temp/mock_pipe_tes.go
@@ -2,11 +2,10 @@ package test
 
 import (
 	//"fmt"
-	"github.com/androlo/blockchain_rpc/server"
-	edb "github.com/androlo/blockchain_rpc/erisdb"
-	ep "github.com/androlo/blockchain_rpc/erisdb/pipe"
-	tc "github.com/androlo/blockchain_rpc/test/client"
-	"github.com/androlo/blockchain_rpc/test/mock"
+	"github.com/eris-ltd/erisdb/server"
+	edb "github.com/eris-ltd/erisdb/erisdb"
+	tc "github.com/eris-ltd/erisdb/test/client"
+	"github.com/eris-ltd/erisdb/test/mock"
 	"github.com/stretchr/testify/suite"
 	"testing"
 	"time"
@@ -32,7 +31,8 @@ func (this *MockPipeSuite) SetupSuite() {
 
 	edbwss := edb.NewErisDbWsService(&edb.TCodec{}, mockPipe)
 	wsServer := server.NewWebSocketServer(MAX_CONNS, edbwss)
-	proc, errServe := server.Serve(nil, wsServer)
+	proc := server.NewServeProcess(nil, wsServer)
+	errServe := proc.Start()
 	if errServe != nil {
 		panic(errServe.Error())
 	}
@@ -54,7 +54,7 @@ func (this *MockPipeSuite) TearDownSuite() {
 }
 
 func (this *MockPipeSuite) TestClientAccountList() {
-	result, err := this.client.AccountList(&ep.AccountsParam{})
+	result, err := this.client.AccountList(&edb.AccountsParam{})
 	this.NoError(err)
 	this.Equal(result, this.mockData.Accounts, "Accounts not the same")
 }
-- 
GitLab