aboutsummaryrefslogtreecommitdiffstats
path: root/server.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-10 06:15:51 +0800
committerobscuren <geffobscura@gmail.com>2014-01-10 06:15:51 +0800
commit849408dda60fe32d7abb78d103b09ca0bc7b5a60 (patch)
treeb066b834e8e7b2182977fc9f784c821fad47e380 /server.go
parent01740695cda7fe27c53f0fa078732fa5a15a88a5 (diff)
downloadgo-tangerine-849408dda60fe32d7abb78d103b09ca0bc7b5a60.tar
go-tangerine-849408dda60fe32d7abb78d103b09ca0bc7b5a60.tar.gz
go-tangerine-849408dda60fe32d7abb78d103b09ca0bc7b5a60.tar.bz2
go-tangerine-849408dda60fe32d7abb78d103b09ca0bc7b5a60.tar.lz
go-tangerine-849408dda60fe32d7abb78d103b09ca0bc7b5a60.tar.xz
go-tangerine-849408dda60fe32d7abb78d103b09ca0bc7b5a60.tar.zst
go-tangerine-849408dda60fe32d7abb78d103b09ca0bc7b5a60.zip
Peer handling
Diffstat (limited to 'server.go')
-rw-r--r--server.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/server.go b/server.go
index d7718a8a6..feaf61076 100644
--- a/server.go
+++ b/server.go
@@ -2,7 +2,8 @@ package main
import (
"container/list"
- "time"
+ "net"
+ "log"
)
var Db *LDBDatabase
@@ -36,12 +37,27 @@ func NewServer() (*Server, error) {
return server, nil
}
+func (s *Server) AddPeer(conn net.Conn) {
+ s.peers.PushBack(NewPeer(conn, s))
+}
+
// Start the server
func (s *Server) Start() {
// For now this function just blocks the main thread
+ ln, err := net.Listen("tcp", ":12345")
+ if err != nil {
+ log.Fatal(err)
+ }
+
go func() {
for {
- time.Sleep( time.Second )
+ conn, err := ln.Accept()
+ if err != nil {
+ log.Println(err)
+ continue
+ }
+
+ go s.AddPeer(conn)
}
}()
}