Skip to content

Commit

Permalink
Fix socks5x
Browse files Browse the repository at this point in the history
  • Loading branch information
wizawu committed Feb 10, 2021
1 parent 2587638 commit d84c9bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions roles/socks5x/files/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ export function countConnErr(domain: string) {
sum(case when choose = 0 then 1 else 0 end) as error0,
sum(case when choose = 1 then 1 else 0 end) as error1
from history
where domain = @domain and duration < 32000 and traffic < 32 and error > '' and time > @lastDay
`).get({ domain, lastDay: Date.now() - 86400 * 1000 })
where domain = @domain and traffic <= 26 and (error > '' or duration < 1000)
`).get({ domain })
}

export function countReadErr(domain: string, prefer: number) {
db.exec(`delete from history where time < ${Date.now() - 30 * 86400 * 1000}`)
return db.prepare(`
select
sum(case when error = '' then 1 else 0 end) as ok,
sum(case when error > '' then 1 else 0 end) as fail
from history
where domain = @domain and choose = @prefer and traffic > 32
where domain = @domain and choose = @prefer and traffic > 26
`).get({ domain, prefer })
}

export function trimHistory(days: number) {
db.exec(`delete from history where time < ${Date.now() - days * 86400 * 1000}`)
}
1 change: 1 addition & 0 deletions roles/socks5x/files/src/switcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function select(upstream: string): Backend {
let result = store.selectDomain(upstream)
if (result) {
setTimeout(() => {
store.trimHistory(30)
let { error0, error1 } = store.countConnErr(upstream)
if (error0 > error1) {
store.updateDomain(upstream, 1)
Expand Down

0 comments on commit d84c9bf

Please sign in to comment.