Skip to content

Commit

Permalink
let there be Browsers Unbounded
Browse files Browse the repository at this point in the history
  • Loading branch information
noahlevenson committed Oct 25, 2023
1 parent 1566f60 commit a492981
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 107 deletions.
4 changes: 2 additions & 2 deletions clientcore/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"sync"
"time"

"github.com/getlantern/broflake/common"
"github.com/getlantern/broflake/otel"
"github.com/getlantern/unbounded/common"
"github.com/getlantern/unbounded/otel"
"github.com/pion/webrtc/v3"
)

Expand Down
2 changes: 1 addition & 1 deletion clientcore/egress_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"nhooyr.io/websocket"

"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/common"
)

func NewEgressConsumerWebSocket(options *EgressOptions, wg *sync.WaitGroup) *WorkerFSM {
Expand Down
2 changes: 1 addition & 1 deletion clientcore/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/pion/webrtc/v3"

"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/common"
)

func NewProducerWebRTC(options *WebRTCOptions, wg *sync.WaitGroup) *WorkerFSM {
Expand Down
2 changes: 1 addition & 1 deletion clientcore/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math/rand"
"sync"

"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/common"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions clientcore/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/quic-go/quic-go"

"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/common"
)

type ReliableStreamLayer interface {
Expand All @@ -38,13 +38,13 @@ type QUICLayerOptions struct {
CA *x509.CertPool
}

func NewQUICLayer(bfconn *BroflakeConn, qopt *QUICLayerOptions) (*QUICLayer, error) {
func NewQUICLayer(bfconn *BUConn, qopt *QUICLayerOptions) (*QUICLayer, error) {
q := &QUICLayer{
bfconn: bfconn,
tlsConfig: &tls.Config{
ServerName: qopt.ServerName,
InsecureSkipVerify: qopt.InsecureSkipVerify,
NextProtos: []string{"broflake"},
NextProtos: []string{"unbounded"},
RootCAs: qopt.CA,
},
eventualConn: newEventualConn(),
Expand All @@ -54,7 +54,7 @@ func NewQUICLayer(bfconn *BroflakeConn, qopt *QUICLayerOptions) (*QUICLayer, err
}

type QUICLayer struct {
bfconn *BroflakeConn
bfconn *BUConn
tlsConfig *tls.Config
eventualConn *eventualConn
mx sync.RWMutex
Expand Down
2 changes: 1 addition & 1 deletion clientcore/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package clientcore
import (
"sync"

"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/common"
)

// A tableRouter is a multiplexer/demultiplexer which functions as the interface to a WorkerTable,
Expand Down
6 changes: 3 additions & 3 deletions clientcore/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ func NewDefaultEgressOptions() *EgressOptions {
}
}

type BroflakeOptions struct {
type BUOptions struct {
ClientType string
CTableSize int
PTableSize int
BusBufferSz int
Netstated string
}

func NewDefaultBroflakeOptions() *BroflakeOptions {
return &BroflakeOptions{
func NewDefaultBUOptions() *BUOptions {
return &BUOptions{
ClientType: "desktop",
CTableSize: 5,
PTableSize: 5,
Expand Down
6 changes: 3 additions & 3 deletions clientcore/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"sync/atomic"
"time"

"github.com/getlantern/broflake/common"
netstatecl "github.com/getlantern/broflake/netstate/client"
"github.com/getlantern/unbounded/common"
netstatecl "github.com/getlantern/unbounded/netstate/client"
)

const (
uiRefreshHz = 4
)

type UI interface {
Init(bf *BroflakeEngine)
Init(bu *BUEngine)

Start()

Expand Down
14 changes: 7 additions & 7 deletions clientcore/ui_default_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ import (

type UIImpl struct {
UI
BroflakeEngine *BroflakeEngine
BUEngine *BUEngine
}

func (ui *UIImpl) Init(bf *BroflakeEngine) {
ui.BroflakeEngine = bf
func (ui *UIImpl) Init(bu *BUEngine) {
ui.BUEngine = bu
}

func (ui UIImpl) Start() {
ui.BroflakeEngine.start()
ui.BUEngine.start()
}

func (ui UIImpl) Stop() {
ui.BroflakeEngine.stop()
ui.BUEngine.stop()
}

func (ui UIImpl) Debug() {
ui.BroflakeEngine.debug()
ui.BUEngine.debug()
}

func (ui UIImpl) OnReady() {
// TODO: do something?
}

func (ui UIImpl) OnStartup() {
ui.BroflakeEngine.start()
ui.BUEngine.start()
}

func (ui UIImpl) OnDownstreamChunk(size int, workerIdx int) {
Expand Down
16 changes: 8 additions & 8 deletions clientcore/ui_wasm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (

type UIImpl struct {
UI
BroflakeEngine *BroflakeEngine
ID string
BUEngine *BUEngine
ID string
}

func (ui *UIImpl) Init(bf *BroflakeEngine) {
ui.BroflakeEngine = bf
func (ui *UIImpl) Init(bu *BUEngine) {
ui.BUEngine = bu

// The notion of 'ID' exists solely to avoid collisions in the JS namespace
ui.ID = strings.Replace("L4NT3RN"+uuid.NewString(), "-", "", -1)

// Construct the JavaScript API for this Broflake instance
// Construct the JavaScript API for this BU instance
js.Global().Set(ui.ID, js.Global().Get("EventTarget").New())

js.Global().Get(ui.ID).Set(
Expand All @@ -43,15 +43,15 @@ func (ui *UIImpl) Init(bf *BroflakeEngine) {
}

func (ui UIImpl) Start() {
ui.BroflakeEngine.start()
ui.BUEngine.start()
}

func (ui UIImpl) Stop() {
ui.BroflakeEngine.stop()
ui.BUEngine.stop()
}

func (ui UIImpl) Debug() {
ui.BroflakeEngine.debug()
ui.BUEngine.debug()
}

func (ui UIImpl) fireEvent(eventName string, detail map[string]interface{}) {
Expand Down
32 changes: 16 additions & 16 deletions clientcore/broflake.go → clientcore/unbounded.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
// broflake.go defines mid-layer abstractions for constructing and describing a Broflake instance
// unbounded.go defines mid-layer abstractions for constructing and describing a BU instance
package clientcore

import (
"fmt"
"runtime"
"sync"

"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/common"
)

type BroflakeEngine struct {
type BUEngine struct {
cTable *WorkerTable
pTable *WorkerTable
ui UI
wg *sync.WaitGroup
}

func NewBroflakeEngine(cTable, pTable *WorkerTable, ui UI, wg *sync.WaitGroup) *BroflakeEngine {
return &BroflakeEngine{cTable, pTable, ui, wg}
func NewBUEngine(cTable, pTable *WorkerTable, ui UI, wg *sync.WaitGroup) *BUEngine {
return &BUEngine{cTable, pTable, ui, wg}
}

func (b *BroflakeEngine) start() {
func (b *BUEngine) start() {
b.cTable.Start()
b.pTable.Start()
common.Debug("▶ Broflake started!")
common.Debug("▶ BU started!")
}

func (b *BroflakeEngine) stop() {
func (b *BUEngine) stop() {
b.cTable.Stop()
b.pTable.Stop()

go func() {
b.wg.Wait()
common.Debug("■ Broflake stopped.")
common.Debug("■ BU stopped.")
b.ui.OnReady()
}()
}

func (b *BroflakeEngine) debug() {
func (b *BUEngine) debug() {
common.Debugf("NumGoroutine: %v", runtime.NumGoroutine())
}

func NewBroflake(bfOpt *BroflakeOptions, rtcOpt *WebRTCOptions, egOpt *EgressOptions) (bfconn *BroflakeConn, ui *UIImpl, err error) {
func NewBU(bfOpt *BUOptions, rtcOpt *WebRTCOptions, egOpt *EgressOptions) (bfconn *BUConn, ui *UIImpl, err error) {
if bfOpt.ClientType != "desktop" && bfOpt.ClientType != "widget" {
err = fmt.Errorf("Invalid clientType '%v\n'", bfOpt.ClientType)
common.Debugf(err.Error())
Expand All @@ -56,7 +56,7 @@ func NewBroflake(bfOpt *BroflakeOptions, rtcOpt *WebRTCOptions, egOpt *EgressOpt
var wgReady sync.WaitGroup

if bfOpt == nil {
bfOpt = NewDefaultBroflakeOptions()
bfOpt = NewDefaultBUOptions()
}

if rtcOpt == nil {
Expand All @@ -68,7 +68,7 @@ func NewBroflake(bfOpt *BroflakeOptions, rtcOpt *WebRTCOptions, egOpt *EgressOpt
}

// The boot DAG:
// build cTable/pTable -> build the Broflake struct -> run ui.Init -> set up the bus and bind
// build cTable/pTable -> build the BU struct -> run ui.Init -> set up the bus and bind
// the upstream/downstream handlers -> build cRouter/pRouter -> start the bus, init the routers,
// call onStartup and onReady. This dependency graph currently requires us to implement two
// switches on clientType during the boot process, which can probably be improved upon.
Expand Down Expand Up @@ -104,11 +104,11 @@ func NewBroflake(bfOpt *BroflakeOptions, rtcOpt *WebRTCOptions, egOpt *EgressOpt
pTable = NewWorkerTable(pfsms)
}

// Step 2: Build Broflake
broflake := NewBroflakeEngine(cTable, pTable, ui, &wgReady)
// Step 2: Build BU
unbounded := NewBUEngine(cTable, pTable, ui, &wgReady)

// Step 3: Init the UI (this constructs and exposes the JavaScript API as required)
ui.Init(broflake)
ui.Init(unbounded)

// Step 4: Set up the bus, bind upstream and downstream UI handlers
var bus = NewIpcObserver(
Expand Down
16 changes: 8 additions & 8 deletions clientcore/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ import (

"github.com/google/uuid"

"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/common"
)

type BroflakeConn struct {
type BUConn struct {
net.PacketConn
writeChan chan IPCMsg
readChan chan IPCMsg
addr common.DebugAddr
}

func (c BroflakeConn) LocalAddr() net.Addr {
func (c BUConn) LocalAddr() net.Addr {
return c.addr
}

func (c BroflakeConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
func (c BUConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
msg := <-c.readChan
payload := msg.Data.([]byte)
copy(p, payload)
return len(payload), common.DebugAddr("DEBUG NELSON WUZ HERE"), nil
}

func (c BroflakeConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
func (c BUConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
// TODO: This copy seems necessary to avoid a data race
b := make([]byte, len(p))
copy(b, p)
Expand All @@ -49,7 +49,7 @@ func (c BroflakeConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return len(b), nil
}

func NewProducerUserStream(wg *sync.WaitGroup) (*BroflakeConn, *WorkerFSM) {
func NewProducerUserStream(wg *sync.WaitGroup) (*BUConn, *WorkerFSM) {
worker := NewWorkerFSM(wg, []FSMstate{
FSMstate(func(ctx context.Context, com *ipcChan, input []interface{}) (int, []interface{}) {
// State 0
Expand All @@ -60,12 +60,12 @@ func NewProducerUserStream(wg *sync.WaitGroup) (*BroflakeConn, *WorkerFSM) {
}),
})

bfconn := BroflakeConn{
buconn := BUConn{
PacketConn: &net.UDPConn{},
writeChan: worker.com.tx,
readChan: worker.com.rx,
addr: common.DebugAddr(uuid.NewString()),
}

return &bfconn, worker
return &buconn, worker
}
10 changes: 5 additions & 5 deletions cmd/client_default_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
_ "net/http/pprof"
"os"

"github.com/getlantern/broflake/clientcore"
"github.com/getlantern/broflake/common"
"github.com/getlantern/unbounded/clientcore"
"github.com/getlantern/unbounded/common"
)

var (
Expand All @@ -30,7 +30,7 @@ func main() {
proxyPort = "1080"
}

common.Debugf("Welcome to Broflake %v", common.Version)
common.Debugf("Welcome to Browsers Unbounded %v", common.Version)
common.Debugf("clientType: %v", clientType)
common.Debugf("freddie: %v", freddie)
common.Debugf("egress: %v", egress)
Expand All @@ -41,7 +41,7 @@ func main() {
common.Debugf("serverName: %v", serverName)
common.Debugf("proxyPort: %v", proxyPort)

bfOpt := clientcore.NewDefaultBroflakeOptions()
bfOpt := clientcore.NewDefaultBUOptions()
bfOpt.ClientType = clientType
bfOpt.Netstated = netstated

Expand All @@ -63,7 +63,7 @@ func main() {
egOpt.Addr = egress
}

bfconn, _, err := clientcore.NewBroflake(bfOpt, rtcOpt, egOpt)
bfconn, _, err := clientcore.NewBU(bfOpt, rtcOpt, egOpt)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading

0 comments on commit a492981

Please sign in to comment.