Skip to content

Commit

Permalink
Merge pull request #72 from vvbbnn00/feat-warp-interval
Browse files Browse the repository at this point in the history
feat: Add GET_WARP_DATA_INTERVAL configuration option to support setting the frequency of getting WARP data.
  • Loading branch information
vvbbnn00 authored Feb 27, 2024
2 parents cdce560 + 8b8ea12 commit 92511e1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,19 @@ python3 app.py optimize

以下是可用的环境变量:

| 变量名 | 默认值 | 说明 |
|---------------------|-----------------------------------|------------------------------------------------------------------------------------------------------------|
| DELAY_THRESHOLD | `500` | 延迟阈值,超过该阈值的`IP`将被剔除 |
| DO_GET_WARP_DATA | `True` | 是否刷取`WARP+`流量,若不需要刷取流量,则设置为`False`即可 |
| LOSS_THRESHOLD | `10` | 丢包率阈值,超过该阈值的`IP`将被剔除 |
| PROXY_POOL_URL | `https://getproxy.bzpl.tech/get/` | IP代理池地址,用于刷取`WARP+`流量,您可以自行搭建,参照[proxy_pool](https://github.com/jhao104/proxy_pool) |
| PUBLIC_URL | `` | 部署在公网上时,填写公网`IP`或域名,用于生成订阅链接,比如 `https://subs.zeabur.app` |
| RANDOM_COUNT | `10` | 每次更新订阅随机节点的数量 |
| REOPTIMIZE_INTERVAL | `-1` | 重新选优的时间间隔,单位为秒,若小于等于0,则不会重新选优,否则每隔该时间间隔会重新选优一次,不建议间隔设置过短。 |
| REQUEST_RATE_LIMIT | `0` | 限制X秒一次请求,该功能不太稳定,建议不要开启 |
| SECRET_KEY | `` | 用于保护订阅链接,若不配置,则不需要输入`SECRET_KEY`即可获取订阅链接 |
| SHARE_SUBSCRIPTION | `False` | 若您的站点想要向社区分享订阅,但不想让自己的账户信息被公开或修改,可以设置为`True`,此时,访问订阅链接时,不需要输入`SECRET_KEY`即可获取,而对于其他的操作,仍然需要输入`SECRET_KEY`|
| 变量名 | 默认值 | 说明 |
|------------------------|-----------------------------------|------------------------------------------------------------------------------------------------------------|
| DELAY_THRESHOLD | `500` | 延迟阈值,超过该阈值的`IP`将被剔除 |
| DO_GET_WARP_DATA | `True` | 是否刷取`WARP+`流量,若不需要刷取流量,则设置为`False`即可 |
| GET_WARP_DATA_INTERVAL | `18` | 刷取`WARP+`流量的时间间隔,单位为秒,每隔该时间间隔会刷取一次`WARP+`流量,不建议间隔设置过短。 |

This comment has been minimized.

Copy link
@Alish1234567890

Alish1234567890 Feb 27, 2024

{'result': None, 'success': False, 'errors': [{'code': 1056, 'message': 'Too many connected devices.'}], 'messages': []}

| LOSS_THRESHOLD | `10` | 丢包率阈值,超过该阈值的`IP`将被剔除 |
| PROXY_POOL_URL | `https://getproxy.bzpl.tech/get/` | IP代理池地址,用于刷取`WARP+`流量,您可以自行搭建,参照[proxy_pool](https://github.com/jhao104/proxy_pool) |
| PUBLIC_URL | `` | 部署在公网上时,填写公网`IP`或域名,用于生成订阅链接,比如 `https://subs.zeabur.app` |
| RANDOM_COUNT | `10` | 每次更新订阅随机节点的数量 |
| REOPTIMIZE_INTERVAL | `-1` | 重新选优的时间间隔,单位为秒,若小于等于0,则不会重新选优,否则每隔该时间间隔会重新选优一次,不建议间隔设置过短。 |
| REQUEST_RATE_LIMIT | `0` | 限制X秒一次请求,该功能不太稳定,建议不要开启 |
| SECRET_KEY | `` | 用于保护订阅链接,若不配置,则不需要输入`SECRET_KEY`即可获取订阅链接 |
| SHARE_SUBSCRIPTION | `False` | 若您的站点想要向社区分享订阅,但不想让自己的账户信息被公开或修改,可以设置为`True`,此时,访问订阅链接时,不需要输入`SECRET_KEY`即可获取,而对于其他的操作,仍然需要输入`SECRET_KEY`|

## 🧰 进阶操作

Expand Down
25 changes: 13 additions & 12 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ environment variables.

Here are the available environment variables:

| Variable Name | Default | Description |
|---------------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| DELAY_THRESHOLD | `500` | Delay threshold; IPs exceeding this threshold will be removed. |
| DO_GET_WARP_DATA | `True` | Whether to get `WARP+` data. If set to `False`, the `WARP+` data will not be obtained. |
| LOSS_THRESHOLD | `10` | Packet loss threshold; IPs exceeding this threshold will be removed. |
| PROXY_POOL_URL | `https://getproxy.bzpl.tech/get/` | IP proxy pool address, used to get `WARP+` traffic. You can build it yourself, check [proxy_pool](https://github.com/jhao104/proxy_pool) for more information. |
| PUBLIC_URL | `None` | When deployed on the public network, fill in the public IP or domain name to generate subscription links. for example `https://subs.zeabur.app` |
| RANDOM_COUNT | `10` | Number of randomly selected nodes during each subscription update. |
| REOPTIMIZE_INTERVAL | `-1` | Re-optimization interval in seconds, if less than or equal to 0, re-optimization will not occur, otherwise it will re-optimize every this interval, it is not recommended to set the interval too short. |
| REQUEST_RATE_LIMIT | `0` | Limits requests to once every X seconds. This feature is unstable; it's recommended not to enable it. |
| SECRET_KEY | `None` | Used to protect the subscription link. If not configured, no `SECRET_KEY` input is required to get the link. |
| SHARE_SUBSCRIPTION | `False` | If you want to share subscriptions with the community but doesn't want your account information to be publicly accessible or modified, you can set this to `True`. In this case, accessing the subscription link does not require entering the `SECRET_KEY`, but for other operations, the `SECRET_KEY` is still required. |
| Variable Name | Default | Description |
|------------------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| DELAY_THRESHOLD | `500` | Delay threshold; IPs exceeding this threshold will be removed. |
| DO_GET_WARP_DATA | `True` | Whether to get `WARP+` data. If set to `False`, the `WARP+` data will not be obtained. |
| GET_WARP_DATA_INTERVAL | `18` | Time interval for obtaining `WARP+` data, in seconds. `WARP+` data will be obtained every this interval, it is not recommended to set the interval too short. |
| LOSS_THRESHOLD | `10` | Packet loss threshold; IPs exceeding this threshold will be removed. |
| PROXY_POOL_URL | `https://getproxy.bzpl.tech/get/` | IP proxy pool address, used to get `WARP+` traffic. You can build it yourself, check [proxy_pool](https://github.com/jhao104/proxy_pool) for more information. |
| PUBLIC_URL | `None` | When deployed on the public network, fill in the public IP or domain name to generate subscription links. for example `https://subs.zeabur.app` |
| RANDOM_COUNT | `10` | Number of randomly selected nodes during each subscription update. |
| REOPTIMIZE_INTERVAL | `-1` | Re-optimization interval in seconds, if less than or equal to 0, re-optimization will not occur, otherwise it will re-optimize every this interval, it is not recommended to set the interval too short. |
| REQUEST_RATE_LIMIT | `0` | Limits requests to once every X seconds. This feature is unstable; it's recommended not to enable it. |
| SECRET_KEY | `None` | Used to protect the subscription link. If not configured, no `SECRET_KEY` input is required to get the link. |
| SHARE_SUBSCRIPTION | `False` | If you want to share subscriptions with the community but doesn't want your account information to be publicly accessible or modified, you can set this to `True`. In this case, accessing the subscription link does not require entering the `SECRET_KEY`, but for other operations, the `SECRET_KEY` is still required. |

## 🧰 Advanced Operations

Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

DELAY_THRESHOLD = int(os.environ.get('DELAY_THRESHOLD')) if os.environ.get('DELAY_THRESHOLD') else 500
DO_GET_WARP_DATA = os.environ.get('DO_GET_WARP_DATA', 'true').lower() == 'true'
GET_WARP_DATA_INTERVAL = int(os.environ.get('GET_WARP_DATA_INTERVAL', 18))
HOST = os.environ.get('HOST') or '0.0.0.0'
LOSS_THRESHOLD = int(os.environ.get('LOSS_THRESHOLD')) if os.environ.get('LOSS_THRESHOLD') else 10
PORT = int(os.environ.get('PORT')) if os.environ.get('PORT') else 3000
Expand Down
2 changes: 1 addition & 1 deletion services/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def doUpdateLicenseKey(license_key: str, logger=logging.Logger(__name__)):
return

# Update license key
updateLicenseKey(account, license_key)
updateLicenseKey(account, license_key, logger=logger)

# Save changes to account
account.license_key = license_key
Expand Down
8 changes: 6 additions & 2 deletions services/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ def getAccount(account: Account, proxy=None) -> dict:
return data["account"]


def updateLicenseKey(account: Account, license_key: str, proxy=None) -> dict:
def updateLicenseKey(account: Account, license_key: str, proxy=None, logger=None) -> dict:
"""
Update license key
:param account: account
:param license_key: license key
:param proxy: proxy dict
:param logger: logger
:return:
"""
timestamp = datetime.datetime.now().isoformat()[:-3] + "Z"
Expand All @@ -142,6 +143,10 @@ def updateLicenseKey(account: Account, license_key: str, proxy=None) -> dict:
headers={"Authorization": f"Bearer {account.token}"},
json=data, proxies=proxy)

if response.status_code >= 400:
if logger:
logger.error(f"Failed to update license key, response: {response.text}")

response.raise_for_status()

return response.json()["result"]
Expand Down Expand Up @@ -181,4 +186,3 @@ def getClientConfig(proxy=None) -> dict:
response.raise_for_status()

return response.json()["result"]

13 changes: 9 additions & 4 deletions services/scheduled_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from apscheduler.schedulers.background import BackgroundScheduler

from config import DO_GET_WARP_DATA, REOPTIMIZE_INTERVAL
from config import DO_GET_WARP_DATA, REOPTIMIZE_INTERVAL, GET_WARP_DATA_INTERVAL
from services.tasks import doAddDataTaskOnce, saveAccount, reoptimizeEntryPoints


Expand All @@ -19,9 +19,14 @@ def main(logger=None):
scheduler = BackgroundScheduler()
logger.info(f"Start scheduler.")

if DO_GET_WARP_DATA:
logger.info(f"DO_GET_WARP_DATA is True, will fetch WARP data per 18 seconds.")
scheduler.add_job(doAddDataTaskOnce, 'interval', seconds=18, args=[None, logger])
if DO_GET_WARP_DATA and GET_WARP_DATA_INTERVAL > 0:
logger.info(f"DO_GET_WARP_DATA is True, will fetch WARP data per {GET_WARP_DATA_INTERVAL} seconds.")

# Check if the GET_WARP_DATA_INTERVAL is too small
if GET_WARP_DATA_INTERVAL < 18:
logger.warning("To avoid 429 error, GET_WARP_DATA_INTERVAL is recommended to be set larger than 18")

scheduler.add_job(doAddDataTaskOnce, 'interval', seconds=GET_WARP_DATA_INTERVAL, args=[None, logger])

if REOPTIMIZE_INTERVAL > 0:
if sys.platform == "win32":
Expand Down

0 comments on commit 92511e1

Please sign in to comment.