Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Snowflake
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
trinity-1686a
Snowflake
Commits
657aaa6b
Verified
Commit
657aaa6b
authored
3 years ago
by
shelikhoo
Browse files
Options
Downloads
Patches
Plain Diff
Refactor event logger setting into function call
See also:
!67 (comment 2770482)
parent
55bf117d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/lib/snowflake.go
+13
-4
13 additions, 4 deletions
client/lib/snowflake.go
client/snowflake.go
+1
-6
1 addition, 6 deletions
client/snowflake.go
with
14 additions
and
10 deletions
client/lib/snowflake.go
+
13
−
4
View file @
657aaa6b
...
...
@@ -71,6 +71,10 @@ func (addr dummyAddr) String() string { return "dummy" }
// https://github.com/Pluggable-Transports/Pluggable-Transports-spec/blob/master/releases/PTSpecV2.1/Pluggable%20Transport%20Specification%20v2.1%20-%20Go%20Transport%20API.pdf
type
Transport
struct
{
dialer
*
WebRTCDialer
// EventDispatcher is the event bus for snowflake events.
// When an important event happens, it will be distributed here.
eventDispatcher
event
.
SnowflakeEventDispatcher
}
// ClientConfig defines how the SnowflakeClient will connect to the broker and Snowflake proxies.
...
...
@@ -93,9 +97,6 @@ type ClientConfig struct {
// Max is the maximum number of snowflake proxy peers that the client should attempt to
// connect to. Defaults to 1.
Max
int
// EventDispatcher is the event bus for snowflake events.
// When an important event happens, it will be distributed here.
EventDispatcher
event
.
SnowflakeEventDispatcher
}
// NewSnowflakeClient creates a new Snowflake transport client that can spawn multiple
...
...
@@ -135,7 +136,8 @@ func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
if
config
.
Max
>
max
{
max
=
config
.
Max
}
transport
:=
&
Transport
{
dialer
:
NewWebRTCDialer4E
(
broker
,
iceServers
,
max
,
config
.
EventDispatcher
)}
eventsLogger
:=
event
.
NewSnowflakeEventDispatcher
()
transport
:=
&
Transport
{
dialer
:
NewWebRTCDialer4E
(
broker
,
iceServers
,
max
,
eventsLogger
),
eventDispatcher
:
eventsLogger
}
return
transport
,
nil
}
...
...
@@ -191,6 +193,13 @@ func (t *Transport) Dial() (net.Conn, error) {
cleanup
=
nil
return
&
SnowflakeConn
{
Stream
:
stream
,
sess
:
sess
,
pconn
:
pconn
,
snowflakes
:
snowflakes
},
nil
}
func
(
t
*
Transport
)
AddSnowflakeEventListener
(
receiver
event
.
SnowflakeEventReceiver
)
{
t
.
eventDispatcher
.
AddSnowflakeEventListener
(
receiver
)
}
func
(
t
*
Transport
)
RemoveSnowflakeEventListener
(
receiver
event
.
SnowflakeEventReceiver
)
{
t
.
eventDispatcher
.
RemoveSnowflakeEventListener
(
receiver
)
}
// SetRendezvousMethod sets the rendezvous method to the Snowflake broker.
func
(
t
*
Transport
)
SetRendezvousMethod
(
r
RendezvousMethod
)
{
...
...
This diff is collapsed.
Click to expand it.
client/snowflake.go
+
1
−
6
View file @
657aaa6b
...
...
@@ -17,7 +17,6 @@ import (
pt
"git.torproject.org/pluggable-transports/goptlib.git"
sf
"git.torproject.org/pluggable-transports/snowflake.git/v2/client/lib"
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/event"
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog"
)
...
...
@@ -91,6 +90,7 @@ func socksAcceptLoop(ln *pt.SocksListener, config sf.ClientConfig, shutdown chan
log
.
Println
(
"Failed to start snowflake transport: "
,
err
)
return
}
transport
.
AddSnowflakeEventListener
(
sf
.
NewPTEventLogger
())
err
=
conn
.
Grant
(
&
net
.
TCPAddr
{
IP
:
net
.
IPv4zero
,
Port
:
0
})
if
err
!=
nil
{
log
.
Printf
(
"conn.Grant error: %s"
,
err
)
...
...
@@ -171,10 +171,6 @@ func main() {
iceAddresses
:=
strings
.
Split
(
strings
.
TrimSpace
(
*
iceServersCommas
),
","
)
eventLogger
:=
event
.
NewSnowflakeEventDispatcher
()
eventLogger
.
AddSnowflakeEventListener
(
sf
.
NewPTEventLogger
())
config
:=
sf
.
ClientConfig
{
BrokerURL
:
*
brokerURL
,
AmpCacheURL
:
*
ampCacheURL
,
...
...
@@ -182,7 +178,6 @@ func main() {
ICEAddresses
:
iceAddresses
,
KeepLocalAddresses
:
*
keepLocalAddresses
||
*
oldKeepLocalAddresses
,
Max
:
*
max
,
EventDispatcher
:
eventLogger
,
}
// Begin goptlib client process.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment