diff options
author | obscuren <geffobscura@gmail.com> | 2014-01-10 06:15:51 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-01-10 06:15:51 +0800 |
commit | 849408dda60fe32d7abb78d103b09ca0bc7b5a60 (patch) | |
tree | b066b834e8e7b2182977fc9f784c821fad47e380 /server.go | |
parent | 01740695cda7fe27c53f0fa078732fa5a15a88a5 (diff) | |
download | go-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.go | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -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) } }() } |