This repository has been archived by the owner on Dec 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from deputinizer/response-stream
feature: 2 algorithms Website-specific workers and Round robin +DNS
- Loading branch information
Showing
50 changed files
with
5,240 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package customresolver | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"time" | ||
|
||
"github.com/erkexzcx/stoppropaganda/internal/spdnsclient" | ||
"github.com/erkexzcx/stoppropaganda/internal/targets" | ||
"github.com/patrickmn/go-cache" | ||
) | ||
|
||
var DnsCache *cache.Cache | ||
|
||
func MakeDNSConfig() (conf *spdnsclient.SPDNSConfig) { | ||
conf = &spdnsclient.SPDNSConfig{ | ||
Ndots: 1, | ||
Timeout: 5 * time.Second, | ||
Attempts: 2, | ||
} | ||
conf.Servers = targets.ReferenceDNSServersForHTTP | ||
|
||
if len(conf.Search) == 0 { | ||
conf.Search = spdnsclient.DnsDefaultSearch() | ||
} | ||
return | ||
} | ||
|
||
var MasterStopPropagandaResolver = &CustomResolver{ | ||
FirstResolver: &spdnsclient.SPResolver{ | ||
|
||
CustomDNSConfig: MakeDNSConfig(), | ||
}, | ||
ParentResolver: net.DefaultResolver, | ||
} | ||
|
||
type CustomResolver struct { | ||
FirstResolver *spdnsclient.SPResolver | ||
ParentResolver *net.Resolver | ||
} | ||
type Resolver interface { | ||
LookupIPAddr(context.Context, string) (names []net.IPAddr, err error) | ||
} | ||
|
||
func (cr *CustomResolver) LookupIPAddr(ctx context.Context, host string) (names []net.IPAddr, err error) { | ||
if c, found := DnsCache.Get(host); found { | ||
return c.([]net.IPAddr), nil | ||
} | ||
names, err = cr.FirstResolver.LookupIPAddr(ctx, host) | ||
if err == nil { | ||
DnsCache.SetDefault(host, names) | ||
return | ||
} | ||
names, err = cr.ParentResolver.LookupIPAddr(ctx, host) | ||
if err == nil { | ||
DnsCache.SetDefault(host, names) | ||
return | ||
} | ||
return | ||
} | ||
|
||
func init() { | ||
DnsCache = cache.New(5*time.Minute, 10*time.Minute) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.