serve accepts connections from the given TCP listener and dispatches each connection to the RPC server. Connections are only accepted from localhost and the seesaw node that we are configured to peer with.
(l *net.TCPListener)
| 265 | // connection to the RPC server. Connections are only accepted from localhost |
| 266 | // and the seesaw node that we are configured to peer with. |
| 267 | func (s *syncServer) serve(l *net.TCPListener) error { |
| 268 | defer l.Close() |
| 269 | |
| 270 | s.server = rpc.NewServer() |
| 271 | s.server.Register(&SeesawSync{s}) |
| 272 | |
| 273 | for { |
| 274 | c, err := l.AcceptTCP() |
| 275 | if err != nil { |
| 276 | if ne, ok := err.(net.Error); ok && ne.Temporary() { |
| 277 | time.Sleep(100 * time.Millisecond) |
| 278 | continue |
| 279 | } |
| 280 | return err |
| 281 | } |
| 282 | raddr := c.RemoteAddr().String() |
| 283 | host, _, err := net.SplitHostPort(raddr) |
| 284 | if err != nil { |
| 285 | log.Errorf("Failed to parse remote address %q: %v", raddr, err) |
| 286 | c.Close() |
| 287 | continue |
| 288 | } |
| 289 | rip := net.ParseIP(host) |
| 290 | if rip == nil || (!rip.IsLoopback() && !rip.Equal(s.engine.config.Peer.IPv4Addr) && !rip.Equal(s.engine.config.Peer.IPv6Addr)) { |
| 291 | log.Warningf("Rejecting connection from non-peer (%s)...", rip) |
| 292 | c.Close() |
| 293 | continue |
| 294 | } |
| 295 | log.Infof("Sync connection established from %s", rip) |
| 296 | go s.server.ServeConn(c) |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | // notify queues a synchronisation notification with each of the active |
| 301 | // synchronisation sessions. |