Skip to content

Commit

Permalink
Allow to specify listen address
Browse files Browse the repository at this point in the history
This allows to bind to a specific network address, e.g. the loopback
interface's address.

New config parameters: listenAddr and tlsListenAddr

They can be set to an IPv4 or IPv6 address.
  • Loading branch information
mstilkerich authored and Frederik Schwan committed Oct 2, 2022
1 parent 8cec7c8 commit 4d4ce18
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion configs/xapsd/xapsd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ loglevel: info
# This sets the location of the file.
databaseFile: /var/lib/xapsd/database.json

# xapsd listens ona a socket for http/https requests from the dovecot plugin. This sets the port number of the socket.
# xapsd listens on a socket for http/https requests from the dovecot plugin.
# This sets the address and port number of the listen socket.
listenAddr: '[::1]'
port: 11619

# xapsd is able to listen on a HTTPS Socket to allow HTTP/2 to be used
Expand All @@ -16,6 +18,7 @@ port: 11619
# !!! direct usage with the plugin is discouraged and unsupported
tlsCertfile:
tlsKeyfile:
tlsListenAddr:
tlsPort: 11620

# Notifications that are not initiated by new messages are not sent immediately for two reasons:
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ type (
LogLevel string
DatabaseFile string
Port string
ListenAddr string
CheckInterval uint
Delay uint
AppleId string
AppleIdHashedPassword string
TlsCertfile string
TlsKeyfile string
TlsPort string
TlsListenAddr string
}
)

Expand Down
8 changes: 4 additions & 4 deletions internal/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func NewHttpSocket(config *config.Config, db *database.Database, apns *Apns) {
router.POST("/notify", httpSocket.handleNotify)
if len(config.TlsCertfile) > 0 || len(config.TlsKeyfile) > 0 {
go func() {
err := http.ListenAndServeTLS(":"+config.TlsPort, config.TlsCertfile, config.TlsKeyfile, router)
err := http.ListenAndServeTLS(config.TlsListenAddr+":"+config.TlsPort, config.TlsCertfile, config.TlsKeyfile, router)
if err != nil {
log.Fatalf("Could not listen on Port %s: %s", config.TlsPort, err)
log.Fatalf("Could not listen on address %s:%s: %s", config.TlsListenAddr, config.TlsPort, err)
}
}()
}
err := http.ListenAndServe(":"+config.Port, router)
err := http.ListenAndServe(config.ListenAddr+":"+config.Port, router)
if err != nil {
log.Fatalf("Could not listen on Port %s: %s", config.Port, err)
log.Fatalf("Could not listen on address %s:%s: %s", config.ListenAddr, config.Port, err)
}
}

Expand Down

0 comments on commit 4d4ce18

Please sign in to comment.