Skip to content
This repository has been archived by the owner on Dec 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #103 from deputinizer/response-stream
Browse files Browse the repository at this point in the history
feature: 2 algorithms Website-specific workers and Round robin +DNS
  • Loading branch information
erkexzcx authored Mar 5, 2022
2 parents b0d6b68 + 30f0113 commit 3c96057
Show file tree
Hide file tree
Showing 50 changed files with 5,240 additions and 153 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Mykhailo Federov (Vice Prime Minister and Minister of Digital Transformation of
* [dialconcurrency](#dialconcurrency)
* [proxy](#proxy)
* [proxybypass](#proxybypass)
* [algorithm](#algorithm)
- [Web UI](#web-ui)
- [Building from source](#building-from-source)
- [Troubleshooting](#troubleshooting)
Expand Down Expand Up @@ -202,11 +203,36 @@ For example `-proxybypass "localhost"`.

This parameter is only applicable when used with [proxy](#proxy) parameter.

## algorithm

Configuration via command line argument `-algorithm rr` or via environment variable `SP_ALGORITHM="rr"`.

The algorithm defines in what manner you want websites to be DOS'ed. It directly impacts resource usage and performance of this application.

Available algorithms:
- `fair` (Default)
- Known as "workers per website" (specified amount of workers will be divided equally for each website).
- Specifying less workers than websites will result in some websites without workers.
- Uses less CPU and RAM.
- By nature it wastes more traffic and generally has bigger impact.
- `rr`
- Known as "pool of workers" (each worker will take the next pending website from the queue).
- Can be used with as low as 1 worker.
- Uses more CPU and RAM.
- By nature it prioritizes slower websites.

# Web UI

As of now there is no fancy web interface, only a JSON pre-formatted output. You can access it using URL http://127.0.0.1:8049/status
As of now there is no fancy web interface, only a JSON pre-formatted output.

The following endpoints are available:
```
http://127.0.0.1:8049/status
http://127.0.0.1:8049/dnscache
http://127.0.0.1:8049/downloaded
```

For Linux users, you can see status nicely in terminal using `jq` formatter. Examples:
Example usage on Linux:
```bash
# Simple:
curl http://127.0.0.1:8049/status
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ require (

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/klauspost/compress v1.14.4 // indirect
github.com/klauspost/compress v1.15.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
)

require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/valyala/fasthttp v1.33.0
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
golang.org/x/tools v0.1.9 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)

replace github.com/valyala/fasthttp => github.com/deputinizer/fasthttp v1.33.0-discard4
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deputinizer/fasthttp v1.33.0-discard h1:hdB26T32ywsELr0uttlxEltzRxvHHs00xLhlc2Znb+A=
github.com/deputinizer/fasthttp v1.33.0-discard/go.mod h1:eznmi1XLARdqNIktB7brDqBBO0jmJ5bqlqh/wf00U1I=
github.com/deputinizer/fasthttp v1.33.0-discard2 h1:V1B6jiWUqkQlqSMUk3SlqGKAKAm4Tu+vz38RMkFSpgc=
github.com/deputinizer/fasthttp v1.33.0-discard2/go.mod h1:eznmi1XLARdqNIktB7brDqBBO0jmJ5bqlqh/wf00U1I=
github.com/deputinizer/fasthttp v1.33.0-discard3 h1:Z68bkm3uVXpaSvrWUoeitil7Up0BGY96L4jyfan25WA=
github.com/deputinizer/fasthttp v1.33.0-discard3/go.mod h1:eznmi1XLARdqNIktB7brDqBBO0jmJ5bqlqh/wf00U1I=
github.com/deputinizer/fasthttp v1.33.0-discard4 h1:GPSNfgr/CdISxSrPcFxVii9tsDRQ9dX0jC/vhepwfv4=
github.com/deputinizer/fasthttp v1.33.0-discard4/go.mod h1:eznmi1XLARdqNIktB7brDqBBO0jmJ5bqlqh/wf00U1I=
github.com/deputinizer/fasthttp v1.33.0 h1:YwWkMHj7bMA+WEeyAlOCmyceD7A0bwAl8SC9q5DZ/8o=
github.com/deputinizer/fasthttp v1.33.0/go.mod h1:KJRK/MXx0J+yd0c5hlR+s1tIHD72sniU8ZJjl97LIw4=
github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.14.4 h1:eijASRJcobkVtSt81Olfh7JX43osYLwy5krOJo6YEu4=
github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U=
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/miekg/dns v1.1.46 h1:uzwpxRtSVxtcIZmz/4Uz6/Rn7G11DvsaslXoy5LxQio=
github.com/miekg/dns v1.1.46/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
Expand All @@ -24,6 +36,7 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import (
"net"
)

var getIPcachedResolver = &CustomResolver{
ParentResolver: InjectionGoResolver,
}

// Modified to use stoppropaganda's CustomResolver
// so that it caches DNS records
func CustomLookupIP(host string, helperIPBuf []net.IP) ([]net.IP, error) {
addrs, err := getIPcachedResolver.LookupIPAddr(context.Background(), host)
addrs, err := MasterStopPropagandaResolver.LookupIPAddr(context.Background(), host)
if err != nil {
return nil, err
}
Expand Down
64 changes: 64 additions & 0 deletions internal/customresolver/customresolver.go
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"sync/atomic"
"time"

"github.com/erkexzcx/stoppropaganda/internal/stoppropaganda/resolvefix"
"github.com/erkexzcx/stoppropaganda/internal/stoppropaganda/sockshttp"
"github.com/erkexzcx/stoppropaganda/internal/resolvefix"
"github.com/erkexzcx/stoppropaganda/internal/sockshttp"
"github.com/valyala/fasthttp"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func CheckNonPublicTCPEndpoints(addrs []net.TCPAddr) error {
func CheckNonPublicIP(ips []net.IP) error {
for _, ip := range ips {
if IsNonPublic(ip) {
return errors.New("Non public IP detected: " + ip.String())
return errors.New(ip.String() + " - Non public IP detected")
}
}
return nil
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3c96057

Please sign in to comment.