aboutsummaryrefslogtreecommitdiffstats
path: root/server.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2013-12-30 06:54:50 +0800
committerobscuren <obscuren@obscura.com>2013-12-30 06:54:50 +0800
commita926686445929d091c2d9e019b017600168e9e47 (patch)
treea328e4f79148461c076b0bd122c591f0bfd213c2 /server.go
parentad048e9f445ff96b7bfd75c104ab923e1e06754b (diff)
downloadgo-tangerine-a926686445929d091c2d9e019b017600168e9e47.tar
go-tangerine-a926686445929d091c2d9e019b017600168e9e47.tar.gz
go-tangerine-a926686445929d091c2d9e019b017600168e9e47.tar.bz2
go-tangerine-a926686445929d091c2d9e019b017600168e9e47.tar.lz
go-tangerine-a926686445929d091c2d9e019b017600168e9e47.tar.xz
go-tangerine-a926686445929d091c2d9e019b017600168e9e47.tar.zst
go-tangerine-a926686445929d091c2d9e019b017600168e9e47.zip
Added sample server, genesis block, and database interface
Diffstat (limited to 'server.go')
-rw-r--r--server.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/server.go b/server.go
new file mode 100644
index 000000000..0c7488787
--- /dev/null
+++ b/server.go
@@ -0,0 +1,55 @@
+package main
+
+import (
+ "container/list"
+ "time"
+)
+
+type Server struct {
+ // Channel for shutting down the server
+ shutdownChan chan bool
+ // DB interface
+ db *Database
+ // Peers (NYI)
+ peers *list.List
+}
+
+func NewServer() (*Server, error) {
+ db, err := NewDatabase()
+ if err != nil {
+ return nil, err
+ }
+
+ server := &Server{
+ shutdownChan: make(chan bool),
+ db: db,
+ peers: list.New(),
+ }
+
+ return server, nil
+}
+
+// Start the server
+func (s *Server) Start() {
+ // For now this function just blocks the main thread
+ for {
+ time.Sleep( time.Second )
+ }
+}
+
+func (s *Server) Stop() {
+ // Close the database
+ defer s.db.Close()
+
+ // Loop thru the peers and close them (if we had them)
+ for e := s.peers.Front(); e != nil; e = e.Next() {
+ // peer close etc
+ }
+
+ s.shutdownChan <- true
+}
+
+// This function will wait for a shutdown and resumes main thread execution
+func (s *Server) WaitForShutdown() {
+ <- s.shutdownChan
+}