-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
195952f
commit d30f8e6
Showing
6 changed files
with
171 additions
and
18 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,41 @@ | ||
package pow | ||
|
||
import ( | ||
"fmt" | ||
"github.com/tsosunchia/powclient" | ||
"github.com/zu1k/nali/internal/constant" | ||
"net/url" | ||
"os" | ||
"runtime" | ||
) | ||
|
||
const ( | ||
baseURL = "/v3/challenge" | ||
) | ||
|
||
var UserAgent = fmt.Sprintf("Nali-NextTrace %s/%s/%s", constant.Version, runtime.GOOS, runtime.GOARCH) | ||
|
||
func GetToken(fastIp string, host string, port string) (string, error) { | ||
getTokenParams := powclient.NewGetTokenParams() | ||
u := url.URL{Scheme: "https", Host: fastIp + ":" + port, Path: baseURL} | ||
getTokenParams.BaseUrl = u.String() | ||
getTokenParams.SNI = host | ||
getTokenParams.Host = host | ||
getTokenParams.UserAgent = UserAgent | ||
var err error | ||
// 尝试三次RetToken,如果都失败了,异常退出 | ||
for i := 0; i < 3; i++ { | ||
token, err := powclient.RetToken(getTokenParams) | ||
//fmt.Println(token, err) | ||
if err != nil { | ||
continue | ||
} | ||
return token, nil | ||
} | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
fmt.Println("RetToken failed 3 times, exit") | ||
os.Exit(1) | ||
return "", nil | ||
} |
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,13 @@ | ||
package pow | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetToken(t *testing.T) { | ||
token, err := GetToken("103.120.18.35", "api.leo.moe", "443") | ||
fmt.Println(token, err) | ||
assert.NoError(t, err, "GetToken() returned an error") | ||
} |