From 849408dda60fe32d7abb78d103b09ca0bc7b5a60 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 9 Jan 2014 23:15:51 +0100 Subject: Peer handling --- server.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'server.go') 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) } }() } -- cgit v1.2.3