added "VisitedNodes" to message, to prevent re-requesting
This commit is contained in:
parent
d34ca730e4
commit
6b99213ec4
7 changed files with 120 additions and 76 deletions
31
files.go
31
files.go
|
@ -82,10 +82,10 @@ func handleFileSearch(w http.ResponseWriter, query, safe, lang string, page int)
|
||||||
Settings: Settings{UxLang: lang, Safe: safe},
|
Settings: Settings{UxLang: lang, Safe: safe},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugging: Print results before rendering template
|
// // Debugging: Print results before rendering template
|
||||||
for _, result := range combinedResults {
|
// for _, result := range combinedResults {
|
||||||
fmt.Printf("Title: %s, Magnet: %s\n", result.Title, result.Magnet)
|
// fmt.Printf("Title: %s, Magnet: %s\n", result.Title, result.Magnet)
|
||||||
}
|
// }
|
||||||
|
|
||||||
if err := tmpl.Execute(w, data); err != nil {
|
if err := tmpl.Execute(w, data); err != nil {
|
||||||
log.Printf("Failed to render template: %v", err)
|
log.Printf("Failed to render template: %v", err)
|
||||||
|
@ -150,15 +150,18 @@ func fetchFileResults(query, safe, lang string, page int) []TorrentResult {
|
||||||
|
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
log.Printf("No file results found for query: %s, trying other nodes", query)
|
log.Printf("No file results found for query: %s, trying other nodes", query)
|
||||||
results = tryOtherNodesForFileSearch(query, safe, lang, page)
|
results = tryOtherNodesForFileSearch(query, safe, lang, page, []string{hostID})
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryOtherNodesForFileSearch(query, safe, lang string, page int) []TorrentResult {
|
func tryOtherNodesForFileSearch(query, safe, lang string, page int, visitedNodes []string) []TorrentResult {
|
||||||
for _, nodeAddr := range peers {
|
for _, nodeAddr := range peers {
|
||||||
results, err := sendFileSearchRequestToNode(nodeAddr, query, safe, lang, page)
|
if contains(visitedNodes, nodeAddr) {
|
||||||
|
continue // Skip nodes already visited
|
||||||
|
}
|
||||||
|
results, err := sendFileSearchRequestToNode(nodeAddr, query, safe, lang, page, visitedNodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
||||||
continue
|
continue
|
||||||
|
@ -170,19 +173,22 @@ func tryOtherNodesForFileSearch(query, safe, lang string, page int) []TorrentRes
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendFileSearchRequestToNode(nodeAddr, query, safe, lang string, page int) ([]TorrentResult, error) {
|
func sendFileSearchRequestToNode(nodeAddr, query, safe, lang string, page int, visitedNodes []string) ([]TorrentResult, error) {
|
||||||
|
visitedNodes = append(visitedNodes, nodeAddr)
|
||||||
searchParams := struct {
|
searchParams := struct {
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
Safe string `json:"safe"`
|
Safe string `json:"safe"`
|
||||||
Lang string `json:"lang"`
|
Lang string `json:"lang"`
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
ResponseAddr string `json:"responseAddr"`
|
ResponseAddr string `json:"responseAddr"`
|
||||||
|
VisitedNodes []string `json:"visitedNodes"`
|
||||||
}{
|
}{
|
||||||
Query: query,
|
Query: query,
|
||||||
Safe: safe,
|
Safe: safe,
|
||||||
Lang: lang,
|
Lang: lang,
|
||||||
Page: page,
|
Page: page,
|
||||||
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
||||||
|
VisitedNodes: visitedNodes,
|
||||||
}
|
}
|
||||||
|
|
||||||
msgBytes, err := json.Marshal(searchParams)
|
msgBytes, err := json.Marshal(searchParams)
|
||||||
|
@ -323,3 +329,12 @@ func sanitizeFileName(name string) string {
|
||||||
sanitized = regexp.MustCompile(`[^a-zA-Z0-9\-\(\)]`).ReplaceAllString(sanitized, "")
|
sanitized = regexp.MustCompile(`[^a-zA-Z0-9\-\(\)]`).ReplaceAllString(sanitized, "")
|
||||||
return sanitized
|
return sanitized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func contains(slice []string, item string) bool {
|
||||||
|
for _, v := range slice {
|
||||||
|
if v == item {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
20
forums.go
20
forums.go
|
@ -100,7 +100,7 @@ func PerformRedditSearch(query string, safe string, page int) ([]ForumSearchResu
|
||||||
|
|
||||||
func handleForumsSearch(w http.ResponseWriter, query, safe, lang string, page int) {
|
func handleForumsSearch(w http.ResponseWriter, query, safe, lang string, page int) {
|
||||||
results, err := PerformRedditSearch(query, safe, page)
|
results, err := PerformRedditSearch(query, safe, page)
|
||||||
if err != nil || len(results) == 0 || 0 == 0 { // 0 == 0 to force search by other node
|
if err != nil || len(results) == 0 { // 0 == 0 to force search by other node
|
||||||
log.Printf("No results from primary search, trying other nodes")
|
log.Printf("No results from primary search, trying other nodes")
|
||||||
results = tryOtherNodesForForumSearch(query, safe, lang, page)
|
results = tryOtherNodesForForumSearch(query, safe, lang, page)
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func handleForumsSearch(w http.ResponseWriter, query, safe, lang string, page in
|
||||||
|
|
||||||
func tryOtherNodesForForumSearch(query, safe, lang string, page int) []ForumSearchResult {
|
func tryOtherNodesForForumSearch(query, safe, lang string, page int) []ForumSearchResult {
|
||||||
for _, nodeAddr := range peers {
|
for _, nodeAddr := range peers {
|
||||||
results, err := sendSearchRequestToNode(nodeAddr, query, safe, lang, page)
|
results, err := sendSearchRequestToNode(nodeAddr, query, safe, lang, page, []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
||||||
continue
|
continue
|
||||||
|
@ -153,19 +153,31 @@ func tryOtherNodesForForumSearch(query, safe, lang string, page int) []ForumSear
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendSearchRequestToNode(nodeAddr, query, safe, lang string, page int) ([]ForumSearchResult, error) {
|
func sendSearchRequestToNode(nodeAddr, query, safe, lang string, page int, visitedNodes []string) ([]ForumSearchResult, error) {
|
||||||
|
// Check if the current node has already been visited
|
||||||
|
for _, node := range visitedNodes {
|
||||||
|
if node == hostID {
|
||||||
|
return nil, fmt.Errorf("loop detected: this node (%s) has already been visited", hostID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add current node to the list of visited nodes
|
||||||
|
visitedNodes = append(visitedNodes, hostID)
|
||||||
|
|
||||||
searchParams := struct {
|
searchParams := struct {
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
Safe string `json:"safe"`
|
Safe string `json:"safe"`
|
||||||
Lang string `json:"lang"`
|
Lang string `json:"lang"`
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
ResponseAddr string `json:"responseAddr"`
|
ResponseAddr string `json:"responseAddr"`
|
||||||
|
VisitedNodes []string `json:"visitedNodes"`
|
||||||
}{
|
}{
|
||||||
Query: query,
|
Query: query,
|
||||||
Safe: safe,
|
Safe: safe,
|
||||||
Lang: lang,
|
Lang: lang,
|
||||||
Page: page,
|
Page: page,
|
||||||
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
||||||
|
VisitedNodes: visitedNodes,
|
||||||
}
|
}
|
||||||
|
|
||||||
msgBytes, err := json.Marshal(searchParams)
|
msgBytes, err := json.Marshal(searchParams)
|
||||||
|
@ -188,7 +200,7 @@ func sendSearchRequestToNode(nodeAddr, query, safe, lang string, page int) ([]Fo
|
||||||
select {
|
select {
|
||||||
case res := <-resultsChan:
|
case res := <-resultsChan:
|
||||||
return res, nil
|
return res, nil
|
||||||
case <-time.After(20 * time.Second): // Increased timeout duration
|
case <-time.After(20 * time.Second):
|
||||||
return nil, fmt.Errorf("timeout waiting for results from node %s", nodeAddr)
|
return nil, fmt.Errorf("timeout waiting for results from node %s", nodeAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
images.go
32
images.go
|
@ -10,6 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var imageSearchEngines []SearchEngine
|
var imageSearchEngines []SearchEngine
|
||||||
|
var imageResultsChan = make(chan []ImageSearchResult)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
imageSearchEngines = []SearchEngine{
|
imageSearchEngines = []SearchEngine{
|
||||||
|
@ -124,15 +125,18 @@ func fetchImageResults(query, safe, lang string, page int) []ImageSearchResult {
|
||||||
// If no results found after trying all engines
|
// If no results found after trying all engines
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
log.Printf("No image results found for query: %s, trying other nodes", query)
|
log.Printf("No image results found for query: %s, trying other nodes", query)
|
||||||
results = tryOtherNodesForImageSearch(query, safe, lang, page)
|
results = tryOtherNodesForImageSearch(query, safe, lang, page, []string{hostID})
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryOtherNodesForImageSearch(query, safe, lang string, page int) []ImageSearchResult {
|
func tryOtherNodesForImageSearch(query, safe, lang string, page int, visitedNodes []string) []ImageSearchResult {
|
||||||
for _, nodeAddr := range peers {
|
for _, nodeAddr := range peers {
|
||||||
results, err := sendImageSearchRequestToNode(nodeAddr, query, safe, lang, page)
|
if contains(visitedNodes, nodeAddr) {
|
||||||
|
continue // Skip nodes already visited
|
||||||
|
}
|
||||||
|
results, err := sendImageSearchRequestToNode(nodeAddr, query, safe, lang, page, visitedNodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
||||||
continue
|
continue
|
||||||
|
@ -144,19 +148,22 @@ func tryOtherNodesForImageSearch(query, safe, lang string, page int) []ImageSear
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendImageSearchRequestToNode(nodeAddr, query, safe, lang string, page int) ([]ImageSearchResult, error) {
|
func sendImageSearchRequestToNode(nodeAddr, query, safe, lang string, page int, visitedNodes []string) ([]ImageSearchResult, error) {
|
||||||
|
visitedNodes = append(visitedNodes, nodeAddr)
|
||||||
searchParams := struct {
|
searchParams := struct {
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
Safe string `json:"safe"`
|
Safe string `json:"safe"`
|
||||||
Lang string `json:"lang"`
|
Lang string `json:"lang"`
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
ResponseAddr string `json:"responseAddr"`
|
ResponseAddr string `json:"responseAddr"`
|
||||||
|
VisitedNodes []string `json:"visitedNodes"`
|
||||||
}{
|
}{
|
||||||
Query: query,
|
Query: query,
|
||||||
Safe: safe,
|
Safe: safe,
|
||||||
Lang: lang,
|
Lang: lang,
|
||||||
Page: page,
|
Page: page,
|
||||||
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
||||||
|
VisitedNodes: visitedNodes,
|
||||||
}
|
}
|
||||||
|
|
||||||
msgBytes, err := json.Marshal(searchParams)
|
msgBytes, err := json.Marshal(searchParams)
|
||||||
|
@ -179,7 +186,7 @@ func sendImageSearchRequestToNode(nodeAddr, query, safe, lang string, page int)
|
||||||
select {
|
select {
|
||||||
case res := <-imageResultsChan:
|
case res := <-imageResultsChan:
|
||||||
return res, nil
|
return res, nil
|
||||||
case <-time.After(30 * time.Second): // Need to handle this better, setting a static number is stupid
|
case <-time.After(30 * time.Second):
|
||||||
return nil, fmt.Errorf("timeout waiting for results from node %s", nodeAddr)
|
return nil, fmt.Errorf("timeout waiting for results from node %s", nodeAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,3 +204,18 @@ func wrapImageSearchFunc(f func(string, string, string, int) ([]ImageSearchResul
|
||||||
return searchResults, duration, nil
|
return searchResults, duration, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleImageResultsMessage(msg Message) {
|
||||||
|
var results []ImageSearchResult
|
||||||
|
err := json.Unmarshal([]byte(msg.Content), &results)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error unmarshalling image results: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Received image results: %+v", results)
|
||||||
|
// Send results to imageResultsChan
|
||||||
|
go func() {
|
||||||
|
imageResultsChan <- results
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
|
@ -61,21 +61,4 @@ func fetchForumResults(query, safe, lang string, page int) []ForumSearchResult {
|
||||||
|
|
||||||
////// IMAGES /////
|
////// IMAGES /////
|
||||||
|
|
||||||
var imageResultsChan = make(chan []ImageSearchResult)
|
|
||||||
|
|
||||||
func handleImageResultsMessage(msg Message) {
|
|
||||||
var results []ImageSearchResult
|
|
||||||
err := json.Unmarshal([]byte(msg.Content), &results)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error unmarshalling image results: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Received image results: %+v", results)
|
|
||||||
// Send results to imageResultsChan
|
|
||||||
go func() {
|
|
||||||
imageResultsChan <- results
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
////// IMAGES /////
|
////// IMAGES /////
|
||||||
|
|
10
node.go
10
node.go
|
@ -24,6 +24,7 @@ type Message struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
VisitedNodes []string `json:"visitedNodes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CrawlerConfig struct {
|
type CrawlerConfig struct {
|
||||||
|
@ -149,18 +150,17 @@ func interpretMessage(msg Message) {
|
||||||
case "search-file":
|
case "search-file":
|
||||||
handleSearchFileMessage(msg)
|
handleSearchFileMessage(msg)
|
||||||
case "search-forum":
|
case "search-forum":
|
||||||
log.Println("Received search-forum message:", msg.Content)
|
|
||||||
handleSearchForumMessage(msg)
|
handleSearchForumMessage(msg)
|
||||||
case "forum-results":
|
case "forum-results":
|
||||||
handleForumResultsMessage(msg)
|
handleForumResultsMessage(msg)
|
||||||
case "text-results":
|
case "text-results":
|
||||||
handleTextResultsMessage(msg) // need to implement
|
handleTextResultsMessage(msg)
|
||||||
case "image-results":
|
case "image-results":
|
||||||
handleImageResultsMessage(msg) // need to implement
|
handleImageResultsMessage(msg)
|
||||||
case "video-results":
|
case "video-results":
|
||||||
handleVideoResultsMessage(msg) // need to implement
|
handleVideoResultsMessage(msg)
|
||||||
case "file-results":
|
case "file-results":
|
||||||
handleFileResultsMessage(msg) // need to implement
|
handleFileResultsMessage(msg)
|
||||||
default:
|
default:
|
||||||
fmt.Println("Received unknown message type:", msg.Type)
|
fmt.Println("Received unknown message type:", msg.Type)
|
||||||
}
|
}
|
||||||
|
|
16
text.go
16
text.go
|
@ -149,7 +149,7 @@ func fetchTextResults(query, safe, lang string, page int) []TextSearchResult {
|
||||||
// If no results found after trying all engines
|
// If no results found after trying all engines
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
log.Printf("No text results found for query: %s, trying other nodes", query)
|
log.Printf("No text results found for query: %s, trying other nodes", query)
|
||||||
results = tryOtherNodesForTextSearch(query, safe, lang, page)
|
results = tryOtherNodesForTextSearch(query, safe, lang, page, []string{hostID})
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
@ -183,9 +183,12 @@ func wrapTextSearchFunc(f func(string, string, string, int) ([]TextSearchResult,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryOtherNodesForTextSearch(query, safe, lang string, page int) []TextSearchResult {
|
func tryOtherNodesForTextSearch(query, safe, lang string, page int, visitedNodes []string) []TextSearchResult {
|
||||||
for _, nodeAddr := range peers {
|
for _, nodeAddr := range peers {
|
||||||
results, err := sendTextSearchRequestToNode(nodeAddr, query, safe, lang, page)
|
if contains(visitedNodes, nodeAddr) {
|
||||||
|
continue // Skip nodes already visited
|
||||||
|
}
|
||||||
|
results, err := sendTextSearchRequestToNode(nodeAddr, query, safe, lang, page, visitedNodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
||||||
continue
|
continue
|
||||||
|
@ -197,19 +200,22 @@ func tryOtherNodesForTextSearch(query, safe, lang string, page int) []TextSearch
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendTextSearchRequestToNode(nodeAddr, query, safe, lang string, page int) ([]TextSearchResult, error) {
|
func sendTextSearchRequestToNode(nodeAddr, query, safe, lang string, page int, visitedNodes []string) ([]TextSearchResult, error) {
|
||||||
|
visitedNodes = append(visitedNodes, nodeAddr)
|
||||||
searchParams := struct {
|
searchParams := struct {
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
Safe string `json:"safe"`
|
Safe string `json:"safe"`
|
||||||
Lang string `json:"lang"`
|
Lang string `json:"lang"`
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
ResponseAddr string `json:"responseAddr"`
|
ResponseAddr string `json:"responseAddr"`
|
||||||
|
VisitedNodes []string `json:"visitedNodes"`
|
||||||
}{
|
}{
|
||||||
Query: query,
|
Query: query,
|
||||||
Safe: safe,
|
Safe: safe,
|
||||||
Lang: lang,
|
Lang: lang,
|
||||||
Page: page,
|
Page: page,
|
||||||
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
||||||
|
VisitedNodes: visitedNodes,
|
||||||
}
|
}
|
||||||
|
|
||||||
msgBytes, err := json.Marshal(searchParams)
|
msgBytes, err := json.Marshal(searchParams)
|
||||||
|
@ -232,7 +238,7 @@ func sendTextSearchRequestToNode(nodeAddr, query, safe, lang string, page int) (
|
||||||
select {
|
select {
|
||||||
case res := <-textResultsChan:
|
case res := <-textResultsChan:
|
||||||
return res, nil
|
return res, nil
|
||||||
case <-time.After(20 * time.Second): // Increased timeout duration
|
case <-time.After(20 * time.Second):
|
||||||
return nil, fmt.Errorf("timeout waiting for results from node %s", nodeAddr)
|
return nil, fmt.Errorf("timeout waiting for results from node %s", nodeAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
video.go
14
video.go
|
@ -155,7 +155,7 @@ func handleVideoSearch(w http.ResponseWriter, query, safe, lang string, page int
|
||||||
results := fetchVideoResults(query, safe, lang, page)
|
results := fetchVideoResults(query, safe, lang, page)
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
log.Printf("No results from primary search, trying other nodes")
|
log.Printf("No results from primary search, trying other nodes")
|
||||||
results = tryOtherNodesForVideoSearch(query, safe, lang, page)
|
results = tryOtherNodesForVideoSearch(query, safe, lang, page, []string{hostID})
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
|
@ -210,9 +210,12 @@ func fetchVideoResults(query, safe, lang string, page int) []VideoResult {
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryOtherNodesForVideoSearch(query, safe, lang string, page int) []VideoResult {
|
func tryOtherNodesForVideoSearch(query, safe, lang string, page int, visitedNodes []string) []VideoResult {
|
||||||
for _, nodeAddr := range peers {
|
for _, nodeAddr := range peers {
|
||||||
results, err := sendVideoSearchRequestToNode(nodeAddr, query, safe, lang, page)
|
if contains(visitedNodes, nodeAddr) {
|
||||||
|
continue // Skip nodes already visited
|
||||||
|
}
|
||||||
|
results, err := sendVideoSearchRequestToNode(nodeAddr, query, safe, lang, page, visitedNodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
log.Printf("Error contacting node %s: %v", nodeAddr, err)
|
||||||
continue
|
continue
|
||||||
|
@ -224,19 +227,22 @@ func tryOtherNodesForVideoSearch(query, safe, lang string, page int) []VideoResu
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendVideoSearchRequestToNode(nodeAddr, query, safe, lang string, page int) ([]VideoResult, error) {
|
func sendVideoSearchRequestToNode(nodeAddr, query, safe, lang string, page int, visitedNodes []string) ([]VideoResult, error) {
|
||||||
|
visitedNodes = append(visitedNodes, nodeAddr)
|
||||||
searchParams := struct {
|
searchParams := struct {
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
Safe string `json:"safe"`
|
Safe string `json:"safe"`
|
||||||
Lang string `json:"lang"`
|
Lang string `json:"lang"`
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
ResponseAddr string `json:"responseAddr"`
|
ResponseAddr string `json:"responseAddr"`
|
||||||
|
VisitedNodes []string `json:"visitedNodes"`
|
||||||
}{
|
}{
|
||||||
Query: query,
|
Query: query,
|
||||||
Safe: safe,
|
Safe: safe,
|
||||||
Lang: lang,
|
Lang: lang,
|
||||||
Page: page,
|
Page: page,
|
||||||
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
ResponseAddr: fmt.Sprintf("http://localhost:%d/node", config.Port),
|
||||||
|
VisitedNodes: visitedNodes,
|
||||||
}
|
}
|
||||||
|
|
||||||
msgBytes, err := json.Marshal(searchParams)
|
msgBytes, err := json.Marshal(searchParams)
|
||||||
|
|
Loading…
Add table
Reference in a new issue