Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/network/network.go

36 lignes
935 o
Go
Brut Vue normale Historique

2017-05-07 21:51:37 +02:00
package network
import (
"fmt"
2017-05-17 07:58:40 +02:00
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util/log"
2017-05-07 21:51:37 +02:00
"github.com/majestrate/i2p-tools/lib/i2p"
"net"
)
// CreateHTTPListener creates a net.Listener for main http webapp given main config
func CreateHTTPListener(conf *config.Config) (net.Listener, error) {
if conf.I2P != nil {
2017-05-07 21:51:37 +02:00
s := i2p.NewSession(conf.I2P.Name, conf.I2P.Addr, conf.I2P.Keyfile)
err := s.Open()
2017-05-07 21:51:37 +02:00
if s != nil {
log.Infof("i2p address: %s", s.B32Addr())
}
return s, err
2017-05-07 21:51:37 +02:00
}
return net.Listen("tcp", fmt.Sprintf("%s:%d", conf.Host, conf.Port))
2017-05-07 21:51:37 +02:00
}
2017-05-10 19:29:35 +02:00
// CreateScraperSocket creates a UDP Scraper socket
func CreateScraperSocket(conf *config.Config) (net.PacketConn, error) {
if conf.I2P != nil {
2017-05-10 19:29:35 +02:00
log.Fatal("i2p udp scraper not supported")
}
var laddr *net.UDPAddr
laddr, err := net.ResolveUDPAddr("udp", conf.Scrape.Addr)
if err != nil {
return nil, err
}
return net.ListenUDP("udp", laddr)
2017-05-10 19:29:35 +02:00
}