Пример #1
0
// ListenAndServe runs an HTTP server listening at |listeningMultiAddr| with
// the given serve options. The address must be provided in multiaddr format.
//
// TODO intelligently parse address strings in other formats so long as they
// unambiguously map to a valid multiaddr. e.g. for convenience, ":8080" should
// map to "/ip4/0.0.0.0/tcp/8080".
func ListenAndServe(n *core.IpfsNode, listeningMultiAddr string, options ...ServeOption) error {
	addr, err := ma.NewMultiaddr(listeningMultiAddr)
	if err != nil {
		return err
	}

	list, err := manet.Listen(addr)
	if err != nil {
		return err
	}

	// we might have listened to /tcp/0 - lets see what we are listing on
	addr = list.Multiaddr()
	fmt.Printf("API server listening on %s\n", addr)

	return Serve(n, list.NetListener(), options...)
}
Пример #2
0
		app := cnAppInfo{
			identity: n.Identity,
			protocol: proto,
		}

		n.Peerstore.AddAddr(peer, addr, peerstore.TempAddrTTL)

		remote, err := corenet.Dial(n, peer, proto)
		if err != nil {
			res.SetError(err, cmds.ErrNormal)
			return
		}

		switch lnet {
		case "tcp", "tcp4", "tcp6":
			listener, err := manet.Listen(bindAddr)
			if err != nil {
				res.SetError(err, cmds.ErrNormal)
				if err := remote.Close(); err != nil {
					res.SetError(err, cmds.ErrNormal)
				}
				return
			}

			app.address = listener.Multiaddr()
			app.closer = listener
			app.running = true

			go doAccept(&app, remote, listener)

		default: