Skip to content

Commit

Permalink
feat: replace NewPublisherForListener with NewPublisherWithoutServer (#…
Browse files Browse the repository at this point in the history
…56)

because all we really need is an address for the publisher's maddr property
  • Loading branch information
rvagg authored Jun 19, 2023
1 parent 21eb87a commit 5cba614
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions dagsync/httpsync/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ func NewPublisher(address string, lsys ipld.LinkSystem, privKey ic.PrivKey, opti
// is the caller's responsibility. ServeHTTP on the returned Publisher
// can be used to handle requests. handlerPath is the path to handle
// requests on, e.g. "ipni" for `/ipni/...` requests.
//
// DEPRECATED: use NewPublisherWithoutServer(listener.Addr(), ...)
func NewPublisherForListener(listener net.Listener, handlerPath string, lsys ipld.LinkSystem, privKey ic.PrivKey, options ...Option) (*Publisher, error) {
return NewPublisherWithoutServer(listener.Addr().String(), handlerPath, lsys, privKey, options...)
}

// NewPublisherWithoutServer creates a new http publisher for an existing
// network address. When providing an existing network address, running
// the HTTP server is the caller's responsibility. ServeHTTP on the
// returned Publisher can be used to handle requests. handlerPath is the
// path to handle requests on, e.g. "ipni" for `/ipni/...` requests.
func NewPublisherWithoutServer(address string, handlerPath string, lsys ipld.LinkSystem, privKey ic.PrivKey, options ...Option) (*Publisher, error) {
opts, err := getOpts(options)
if err != nil {
return nil, err
Expand All @@ -110,7 +121,11 @@ func NewPublisherForListener(listener net.Listener, handlerPath string, lsys ipl
return nil, fmt.Errorf("could not get peer id from private key: %w", err)
}

maddr, err := manet.FromNetAddr(listener.Addr())
addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
return nil, err
}
maddr, err := manet.FromNetAddr(addr)
if err != nil {
return nil, err
}
Expand All @@ -125,8 +140,6 @@ func NewPublisherForListener(listener net.Listener, handlerPath string, lsys ipl
handlerPath = "/" + handlerPath
}

fmt.Println("w addr", multiaddr.Join(maddr, proto).String())

return &Publisher{
addr: multiaddr.Join(maddr, proto),
closer: io.NopCloser(nil),
Expand Down

0 comments on commit 5cba614

Please sign in to comment.