Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hiddify changes cleaned #25

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions device/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type Peer struct {
inbound *autodrainingInboundQueue // sequential ordering of tun writing
}

trick bool
trick bool
stopCh chan int

cookieGenerator CookieGenerator
trieEntries list.List
Expand All @@ -79,7 +80,7 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {

// create peer
peer := new(Peer)

peer.stopCh = make(chan int, 1)
peer.trick = true
peer.cookieGenerator.Init(pk)
peer.device = device
Expand Down Expand Up @@ -267,6 +268,10 @@ func (peer *Peer) Stop() {
return
}

select {
case peer.stopCh <- 1:
default:
}
peer.device.log.Verbosef("%v - Stopping", peer)

peer.timersStop()
Expand Down
7 changes: 5 additions & 2 deletions device/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ func (peer *Peer) sendRandomPackets() {
return
}

if i < numPackets-1 {
if i < numPackets-1 && peer.isRunning.Load() && !peer.device.isClosed() {
select {
case <-peer.stopCh:
// Wait for a random duration between 20 and 250 milliseconds
time.Sleep(time.Duration(randomInt(20, 250)) * time.Millisecond)
case <-time.After(time.Duration(randomInt(20, 250)) * time.Millisecond):
}
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions warp/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,36 @@ func CheckProfileExists(license string) bool {
}
return isOk
}

func RemoveDevice(account AccountData) error {

headers := map[string]string{
"Content-Type": "application/json",
"User-Agent": "okhttp/3.12.1",
"CF-Client-Version": "a-6.30-3596",
"Authorization": "Bearer " + account.AccessToken,
}

req, err := http.NewRequest("DELETE", "https://api.cloudflareclient.com/v0a3596/reg/"+account.AccountID, nil)
if err != nil {
return err
}

// Set headers
for k, v := range MergeMaps(defaultHeaders, headers) {
req.Header.Set(k, v)
}

// Create HTTP client and execute request
response, err := client.Do(req)
if err != nil {
fmt.Println("sending request to remote server", err)
return err
}

if response.StatusCode != 204 {
return fmt.Errorf("error in deleting account %d %s", response.StatusCode, response.Status)
}

return nil
}
Loading