This was lost in #7217 a while back. --------- Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
+14
-7
@@ -71,9 +71,13 @@ var (
|
|||||||
|
|
||||||
// httpClient is the HTTP client we use for outbound requests. It has a
|
// httpClient is the HTTP client we use for outbound requests. It has a
|
||||||
// timeout and may get further options set during initialization.
|
// timeout and may get further options set during initialization.
|
||||||
var httpClient = &http.Client{
|
var (
|
||||||
Timeout: 30 * time.Second,
|
httpTransport = &http.Transport{}
|
||||||
}
|
httpClient = &http.Client{
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
Transport: httpTransport,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.Lshortfile | log.LstdFlags)
|
log.SetFlags(log.Lshortfile | log.LstdFlags)
|
||||||
@@ -132,9 +136,7 @@ func main() {
|
|||||||
// also come from that address.
|
// also come from that address.
|
||||||
laddr.Port = 0
|
laddr.Port = 0
|
||||||
boundDialer := &net.Dialer{LocalAddr: laddr}
|
boundDialer := &net.Dialer{LocalAddr: laddr}
|
||||||
httpClient.Transport = &http.Transport{
|
httpTransport.DialContext = boundDialer.DialContext
|
||||||
DialContext: boundDialer.DialContext,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(longVer)
|
log.Println(longVer)
|
||||||
@@ -163,6 +165,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Outgoing HTTPS requests may use our certificate for authentication
|
||||||
|
httpTransport.TLSClientConfig = &tls.Config{
|
||||||
|
Certificates: []tls.Certificate{cert},
|
||||||
|
}
|
||||||
|
|
||||||
tlsCfg := &tls.Config{
|
tlsCfg := &tls.Config{
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
NextProtos: []string{protocol.ProtocolName},
|
NextProtos: []string{protocol.ProtocolName},
|
||||||
@@ -277,7 +284,7 @@ func main() {
|
|||||||
for _, pool := range pools {
|
for _, pool := range pools {
|
||||||
pool = strings.TrimSpace(pool)
|
pool = strings.TrimSpace(pool)
|
||||||
if len(pool) > 0 {
|
if len(pool) > 0 {
|
||||||
go poolHandler(pool, uri, mapping, cert)
|
go poolHandler(pool, uri, mapping)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-20
@@ -4,7 +4,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -17,7 +16,7 @@ const (
|
|||||||
httpStatusEnhanceYourCalm = 429
|
httpStatusEnhanceYourCalm = 429
|
||||||
)
|
)
|
||||||
|
|
||||||
func poolHandler(pool string, uri *url.URL, mapping mapping, ownCert tls.Certificate) {
|
func poolHandler(pool string, uri *url.URL, mapping mapping) {
|
||||||
if debug {
|
if debug {
|
||||||
log.Println("Joining", pool)
|
log.Println("Joining", pool)
|
||||||
}
|
}
|
||||||
@@ -32,24 +31,7 @@ func poolHandler(pool string, uri *url.URL, mapping mapping, ownCert tls.Certifi
|
|||||||
uriCopy.String(),
|
uriCopy.String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
poolUrl, err := url.Parse(pool)
|
resp, err := httpClient.Post(pool, "application/json", &b) //nolint:noctx
|
||||||
if err != nil {
|
|
||||||
log.Printf("Could not parse pool url '%s': %v", pool, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client := http.DefaultClient
|
|
||||||
if poolUrl.Scheme == "https" {
|
|
||||||
// Sent our certificate in join request
|
|
||||||
client = &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
Certificates: []tls.Certificate{ownCert},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := client.Post(pool, "application/json", &b)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error joining pool %v: HTTP request: %v", pool, err)
|
log.Printf("Error joining pool %v: HTTP request: %v", pool, err)
|
||||||
time.Sleep(time.Minute)
|
time.Sleep(time.Minute)
|
||||||
|
|||||||
Reference in New Issue
Block a user