Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'valencia' into issue-2721
- Loading branch information
Showing
323 changed files
with
65,995 additions
and
88 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
1 change: 1 addition & 0 deletions
1
src/github.com/getlantern/flashlight/genconfig/proxiedsites/google_domains.txt
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
78 changes: 78 additions & 0 deletions
78
src/github.com/getlantern/flashlight/localdiscovery/localdiscovery.go
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,78 @@ | ||
// Package localdiscovery provides a service for discovering Lantern instances | ||
// in the local network | ||
package localdiscovery | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/getlantern/flashlight/ui" | ||
"github.com/getlantern/golog" | ||
"github.com/getlantern/multicast" | ||
) | ||
|
||
const ( | ||
messageType = `LocalDiscovery` | ||
) | ||
|
||
var ( | ||
log = golog.LoggerFor("flashlight.localdiscovery") | ||
service *ui.Service | ||
mc *multicast.Multicast | ||
lastPeers []multicast.PeerInfo | ||
peersMutex sync.Mutex | ||
) | ||
|
||
// Start begins the local Lantern discovery process | ||
func Start(advertise bool, portToAdvertise string) { | ||
if service != nil { | ||
// Dev error: this service shouldn't be started unless stopped | ||
panic("The " + messageType + " service is already registered") | ||
return | ||
} | ||
|
||
var err error | ||
service, err = ui.Register(messageType, nil, func(write func(interface{}) error) error { | ||
// When connecting the UI we push the current peer list. For this reason, we need | ||
// to hold this list beyond the add/remove events. | ||
return write(buildPeersList()) | ||
}) | ||
if err != nil { | ||
log.Errorf("Unable to register Local Discovery service: %q", err) | ||
return | ||
} | ||
|
||
addOrRemoveCb := func(peer string, peersInfo []multicast.PeerInfo) { | ||
peersMutex.Lock() | ||
lastPeers = peersInfo | ||
peersMutex.Unlock() | ||
|
||
service.Out <- buildPeersList() | ||
} | ||
mc = multicast.JoinMulticast(addOrRemoveCb, addOrRemoveCb) | ||
|
||
if advertise { | ||
mc.SetPayload(portToAdvertise) | ||
mc.StartMulticast() | ||
} | ||
|
||
mc.ListenPeers() | ||
} | ||
|
||
// Stop quits the local Lantern discovery process | ||
func Stop() { | ||
ui.Unregister(messageType) | ||
service = nil | ||
mc.LeaveMulticast() | ||
} | ||
|
||
func buildPeersList() []string { | ||
peersList := make([]string, len(lastPeers)) | ||
|
||
peersMutex.Lock() | ||
for i, peer := range lastPeers { | ||
peersList[i] = "http://" + peer.IP.String() + ":" + peer.Payload | ||
} | ||
peersMutex.Unlock() | ||
|
||
return peersList | ||
} |
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
Oops, something went wrong.