Пример #1
0
func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error {
	os.Remove(cfg.Endpoint) // in case it still exists from a previous run

	l, err := net.Listen("unix", cfg.Endpoint)
	if err != nil {
		return err
	}
	l = fdtrack.WrapListener("ipc", l)
	os.Chmod(cfg.Endpoint, 0600)

	go func() {
		for {
			conn, err := l.Accept()
			if err != nil {
				glog.V(logger.Error).Infof("Error accepting ipc connection - %v\n", err)
				continue
			}

			id := newIpcConnId()
			glog.V(logger.Debug).Infof("New IPC connection with id %06d started\n", id)

			go handle(id, conn, api, codec)
		}

		os.Remove(cfg.Endpoint)
	}()

	glog.V(logger.Info).Infof("IPC service started (%s)\n", cfg.Endpoint)

	return nil
}
Пример #2
0
func listenHTTP(addr string, h http.Handler) (*stopServer, error) {
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return nil, err
	}
	l = fdtrack.WrapListener("rpc", l)
	s := &stopServer{l: l, idle: make(map[net.Conn]struct{})}
	s.Server = &http.Server{
		Addr:         addr,
		Handler:      h,
		ReadTimeout:  serverReadTimeout,
		WriteTimeout: serverWriteTimeout,
		ConnState:    s.connState,
	}
	go s.Serve(l)
	return s, nil
}
Пример #3
0
func (srv *Server) startListening() error {
	// Launch the TCP listener.
	listener, err := net.Listen("tcp", srv.ListenAddr)
	if err != nil {
		return err
	}
	laddr := listener.Addr().(*net.TCPAddr)
	srv.ListenAddr = laddr.String()
	srv.listener = fdtrack.WrapListener("p2p", listener)
	srv.loopWG.Add(1)
	go srv.listenLoop()
	// Map the TCP listening port if NAT is configured.
	if !laddr.IP.IsLoopback() && srv.NAT != nil {
		srv.loopWG.Add(1)
		go func() {
			nat.Map(srv.NAT, srv.quit, "tcp", laddr.Port, laddr.Port, "ethereum p2p")
			srv.loopWG.Done()
		}()
	}
	return nil
}