pkg: listeners: separate out the listeners package
This code will be used in containerd and is quite useful in general to people who want a nice way of creating listeners from proto://address arguments (even supporting socket activation). Separate it out from docker/ so people can use it much more easily. Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
e2664472b6
commit
d61bb3048b
3 changed files with 199 additions and 0 deletions
22
listeners/listeners.go
Normal file
22
listeners/listeners.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package listeners
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/go-connections/sockets"
|
||||
)
|
||||
|
||||
func initTCPSocket(addr string, tlsConfig *tls.Config) (l net.Listener, err error) {
|
||||
if tlsConfig == nil || tlsConfig.ClientAuth != tls.RequireAndVerifyClientCert {
|
||||
logrus.Warn("/!\\ DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
|
||||
}
|
||||
if l, err = sockets.NewTCPSocket(addr, tlsConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := allocateDaemonPort(addr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue