croc/src/models/constants.go

55 lines
1.3 KiB
Go
Raw Normal View History

2018-09-23 15:28:34 +02:00
package models
2020-11-17 19:29:52 +01:00
import (
"context"
"fmt"
"net"
"time"
)
2020-10-13 21:26:11 +02:00
2019-09-07 18:46:04 +02:00
// TCP_BUFFER_SIZE is the maximum packet size
2019-04-30 15:58:57 +02:00
const TCP_BUFFER_SIZE = 1024 * 64
2019-09-07 18:46:04 +02:00
// DEFAULT_RELAY is the default relay used (can be set using --relay)
var (
DEFAULT_RELAY = "croc.schollz.com"
DEFAULT_RELAY6 = "croc6.schollz.com"
DEFAULT_PORT = "9009"
DEFAULT_PASSPHRASE = "pass123"
)
2020-10-13 21:26:11 +02:00
func init() {
2020-11-17 19:29:52 +01:00
DEFAULT_RELAY, _ = lookupIP(DEFAULT_RELAY)
DEFAULT_RELAY += ":" + DEFAULT_PORT
DEFAULT_RELAY6, _ = lookupIP(DEFAULT_RELAY6)
DEFAULT_RELAY6 += "[" + DEFAULT_RELAY6 + "]:" + DEFAULT_PORT
// iprecords, _ := lookupIP(DEFAULT_RELAY)
// for _, ip := range iprecords {
// DEFAULT_RELAY = ip.String() + ":" + DEFAULT_PORT
// }
// iprecords, _ = lookupIP(DEFAULT_RELAY6)
// for _, ip := range iprecords {
// DEFAULT_RELAY6 = "[" + ip.String() + "]:" + DEFAULT_PORT
// }
}
func lookupIP(address string) (ipaddress string, err error) {
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}
2020-11-17 19:35:57 +01:00
return d.DialContext(ctx, "udp", "1.1.1.1")
2020-11-17 19:29:52 +01:00
},
2020-10-13 21:26:11 +02:00
}
2020-11-17 19:29:52 +01:00
ip, err := r.LookupHost(context.Background(), address)
2020-11-17 19:35:57 +01:00
fmt.Println(ip)
2020-11-17 19:29:52 +01:00
if err != nil {
fmt.Println(err)
return
2020-10-13 21:26:11 +02:00
}
2020-11-17 19:29:52 +01:00
ipaddress = ip[0]
return
2020-10-13 21:26:11 +02:00
}