From 757d854facb4112eb3494e19828e328ad28c16f7 Mon Sep 17 00:00:00 2001 From: Andrew Gillis Date: Fri, 15 Sep 2023 02:09:06 -0700 Subject: [PATCH] Option to specify TLS config for publisher (#115) --- dagsync/ipnisync/option.go | 10 ++++++++++ dagsync/ipnisync/publisher.go | 1 + 2 files changed, 11 insertions(+) diff --git a/dagsync/ipnisync/option.go b/dagsync/ipnisync/option.go index 6ba59f2..1481aa0 100644 --- a/dagsync/ipnisync/option.go +++ b/dagsync/ipnisync/option.go @@ -1,6 +1,7 @@ package ipnisync import ( + "crypto/tls" "fmt" "time" @@ -16,6 +17,7 @@ type config struct { streamHost host.Host requireTLS bool httpAddrs []string + tlsConfig *tls.Config } // Option is a function that sets a value in a config. @@ -101,6 +103,14 @@ func WithStreamHost(h host.Host) Option { } } +// WithTLSConfig sets the TLS config for the HTTP server. +func WithTLSConfig(tlsConfig *tls.Config) Option { + return func(c *config) error { + c.tlsConfig = tlsConfig + return nil + } +} + type clientConfig struct { authPeerID bool streamHost host.Host diff --git a/dagsync/ipnisync/publisher.go b/dagsync/ipnisync/publisher.go index 601751f..f830474 100644 --- a/dagsync/ipnisync/publisher.go +++ b/dagsync/ipnisync/publisher.go @@ -105,6 +105,7 @@ func NewPublisher(lsys ipld.LinkSystem, privKey ic.PrivKey, options ...Option) ( StreamHost: opts.streamHost, ListenAddrs: httpListenAddrs, InsecureAllowHTTP: !opts.requireTLS, + TLSConfig: opts.tlsConfig, } pub.pubHost = publisherHost