Merge pull request #15 from D4-project/tcpreuse

Tcpreuse
pull/19/head
Jean-Louis Huynen 2020-05-26 16:18:18 +02:00 committed by GitHub
commit 21256a2ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 27 deletions

View File

@ -200,7 +200,13 @@ func main() {
// copy routine
go d4Copy(d4p, c)
// Block until the rate limiter allow us to continue
<-ratelimiter
select {
case <-ratelimiter:
continue
case <-s:
logger.Println("Exiting")
exit(d4p, 0)
}
} else if d4.retry > 0 {
go func() {
logger.Println(fmt.Sprintf("Sleeping for %.f seconds before retry...", d4.retry.Seconds()))
@ -266,7 +272,7 @@ func d4loadConfig(d4 *d4S) bool {
}
if (*d4).conf.source == "d4server" {
// Parse Input Redis Config
tmp := config.ReadConfigFile(*confdir, "redis_d4")
tmp := string(readConfFile(d4, "redis_d4"))
ss := strings.Split(string(tmp), "/")
if len(ss) <= 1 {
log.Fatal("Missing Database in Redis input config: should be host:port/database_name")
@ -414,33 +420,40 @@ func setReaderWriters(d4 *d4S) bool {
}
isn, dstnet := config.IsNet((*d4).conf.destination)
if isn {
dial := net.Dialer{
Timeout: (*d4).ct,
KeepAlive: (*d4).cka,
FallbackDelay: 0,
}
tlsc := tls.Config{
InsecureSkipVerify: true,
}
if (*d4).cc {
tlsc = tls.Config{
InsecureSkipVerify: false,
RootCAs: &(*d4).ca,
// First, we test whether a usable connection already exist
// (case where the reader run out of data)
switch (*d4).dst.w.(type){
case net.Conn:
// in this case, it's already set up.
default:
dial := net.Dialer{
Timeout: (*d4).ct,
KeepAlive: (*d4).cka,
FallbackDelay: 0,
}
}
if (*d4).ce == true {
conn, errc := tls.DialWithDialer(&dial, "tcp", dstnet, &tlsc)
if errc != nil {
logger.Println(errc)
return false
tlsc := tls.Config{
InsecureSkipVerify: true,
}
(*d4).dst = newD4Writer(conn, (*d4).conf.key)
} else {
conn, errc := dial.Dial("tcp", dstnet)
if errc != nil {
return false
if (*d4).cc {
tlsc = tls.Config{
InsecureSkipVerify: false,
RootCAs: &(*d4).ca,
}
}
if (*d4).ce == true {
conn, errc := tls.DialWithDialer(&dial, "tcp", dstnet, &tlsc)
if errc != nil {
logger.Println(errc)
return false
}
(*d4).dst = newD4Writer(conn, (*d4).conf.key)
} else {
conn, errc := dial.Dial("tcp", dstnet)
if errc != nil {
return false
}
(*d4).dst = newD4Writer(conn, (*d4).conf.key)
}
(*d4).dst = newD4Writer(conn, (*d4).conf.key)
}
} else {
switch (*d4).conf.destination {
@ -466,7 +479,7 @@ func generateUUIDv4() []byte {
if err != nil {
log.Fatal(err)
}
logger.Println(fmt.Sprintf("UUIDv4: %s\n", uuid))
logger.Println(fmt.Sprintf("UUIDv4: %s", uuid))
return uuid.Bytes()
}