Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
b4af146f
Commit
b4af146f
authored
Jan 28, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/net: better dial log.Event
parent
9dac5bb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
9 deletions
+30
-9
p2p/net/conn/dial.go
p2p/net/conn/dial.go
+1
-2
util/eventlog/loggables/loggables.go
util/eventlog/loggables/loggables.go
+29
-7
No files found.
p2p/net/conn/dial.go
View file @
b4af146f
...
...
@@ -28,6 +28,7 @@ func (d *Dialer) String() string {
// Example: d.DialAddr(ctx, peer.Addresses()[0], peer)
func
(
d
*
Dialer
)
Dial
(
ctx
context
.
Context
,
raddr
ma
.
Multiaddr
,
remote
peer
.
ID
)
(
Conn
,
error
)
{
logdial
:=
lgbl
.
Dial
(
"conn"
,
d
.
LocalPeer
,
remote
,
nil
,
raddr
)
logdial
[
"encrypted"
]
=
(
d
.
PrivateKey
!=
nil
)
// log wether this will be an encrypted dial or not.
defer
log
.
EventBegin
(
ctx
,
"connDial"
,
logdial
)
.
Done
()
maconn
,
err
:=
d
.
rawConnDial
(
ctx
,
raddr
,
remote
)
...
...
@@ -53,12 +54,10 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) (
if
d
.
PrivateKey
==
nil
{
log
.
Warning
(
"dialer %s dialing INSECURELY %s at %s!"
,
d
,
remote
,
raddr
)
log
.
Event
(
ctx
,
"connDialInsecure"
,
logdial
)
connOut
=
c
return
}
defer
log
.
EventBegin
(
ctx
,
"connDialEncrypt"
,
logdial
)
.
Done
()
c2
,
err
:=
newSecureConn
(
ctx
,
d
.
PrivateKey
,
c
)
if
err
!=
nil
{
logdial
[
"error"
]
=
err
...
...
util/eventlog/loggables/loggables.go
View file @
b4af146f
...
...
@@ -32,19 +32,41 @@ func Error(e error) log.Loggable {
}
// Dial metadata is metadata for dial events
func
Dial
(
sys
string
,
lid
,
rid
peer
.
ID
,
laddr
,
raddr
ma
.
Multiaddr
)
log
.
LoggableMap
{
m
:=
log
.
Metadata
{
"subsystem"
:
sys
}
func
Dial
(
sys
string
,
lid
,
rid
peer
.
ID
,
laddr
,
raddr
ma
.
Multiaddr
)
DeferredMap
{
m
:=
DeferredMap
{}
m
[
"subsystem"
]
=
sys
if
lid
!=
""
{
m
[
"localPeer"
]
=
lid
.
Pretty
()
m
[
"localPeer"
]
=
func
()
interface
{}
{
return
lid
.
Pretty
()
}
_
=
m
[
"localPeer"
]
.
(
func
()
interface
{})
}
if
laddr
!=
nil
{
m
[
"localAddr"
]
=
laddr
.
String
()
m
[
"localAddr"
]
=
func
()
interface
{}
{
return
laddr
.
String
()
}
}
if
rid
!=
""
{
m
[
"remotePeer"
]
=
rid
.
Pretty
()
m
[
"remotePeer"
]
=
func
()
interface
{}
{
return
rid
.
Pretty
()
}
}
if
raddr
!=
nil
{
m
[
"remoteAddr"
]
=
raddr
.
String
()
m
[
"remoteAddr"
]
=
func
()
interface
{}
{
return
raddr
.
String
()
}
}
return
log
.
LoggableMap
(
m
)
return
m
}
// DeferredMap is a Loggable which may contained deffered values.
type
DeferredMap
map
[
string
]
interface
{}
// Loggable describes objects that can be marshalled into Metadata for logging
func
(
m
DeferredMap
)
Loggable
()
map
[
string
]
interface
{}
{
m2
:=
map
[
string
]
interface
{}{}
for
k
,
v
:=
range
m
{
if
vf
,
ok
:=
v
.
(
func
()
interface
{});
ok
{
// if it's a DeferredVal, call it.
m2
[
k
]
=
vf
()
}
else
{
// else use the value as is.
m2
[
k
]
=
v
}
}
return
m2
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment