Skip to content

Commit fabf26d

Browse files
committed
expose SetContextValue from ClientConn
1 parent 494647d commit fabf26d

File tree

8 files changed

+16
-3
lines changed

8 files changed

+16
-3
lines changed

dtls/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestServer_SetContextValueWithPKI(t *testing.T) {
136136
// set connection context certificate
137137
clientCert, err := x509.ParseCertificate(dtlsConn.ConnectionState().PeerCertificates[0])
138138
require.NoError(t, err)
139-
cc.Session().SetContextValue("client-cert", clientCert)
139+
cc.SetContextValue("client-cert", clientCert)
140140
}
141141
handle := func(w *client.ResponseWriter, r *pool.Message) {
142142
// get certificate from connection context

dtls/session.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (s *Session) Context() context.Context {
8080
return *s.ctx.Load().(*context.Context)
8181
}
8282

83+
// SetContextValue stores the value associated with key to context of connection.
8384
func (s *Session) SetContextValue(key interface{}, val interface{}) {
8485
s.mutex.Lock()
8586
defer s.mutex.Unlock()

examples/dtls/pki/server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func onNewClientConn(cc *client.ClientConn, dtlsConn *piondtls.Conn) {
2525
if err != nil {
2626
log.Fatal(err)
2727
}
28-
cc.Session().SetContextValue("client-cert", clientCert)
28+
cc.SetContextValue("client-cert", clientCert)
2929
cc.AddOnClose(func() {
3030
log.Println("closed connection")
3131
})

tcp/clientconn.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,8 @@ func (cc *ClientConn) Client() *ClientTCP {
441441
func (cc *ClientConn) Sequence() uint64 {
442442
return cc.session.Sequence()
443443
}
444+
445+
// SetContextValue stores the value associated with key to context of connection.
446+
func (cc *ClientConn) SetContextValue(key interface{}, val interface{}) {
447+
cc.session.SetContextValue(key, val)
448+
}

tcp/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestServer_SetContextValueWithPKI(t *testing.T) {
123123
// set connection context certificate
124124
clientCert := tlscon.ConnectionState().PeerCertificates[0]
125125
require.NoError(t, err)
126-
cc.Session().SetContextValue("client-cert", clientCert)
126+
cc.SetContextValue("client-cert", clientCert)
127127
}
128128
handle := func(w *tcp.ResponseWriter, r *pool.Message) {
129129
// get certificate from connection context

tcp/session.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func NewSession(
9191
return s
9292
}
9393

94+
// SetContextValue stores the value associated with key to context of connection.
9495
func (s *Session) SetContextValue(key interface{}, val interface{}) {
9596
s.mutex.Lock()
9697
defer s.mutex.Unlock()

udp/client/clientconn.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,8 @@ func (cc *ClientConn) Process(datagram []byte) error {
524524
func (cc *ClientConn) Client() *Client {
525525
return NewClient(cc)
526526
}
527+
528+
// SetContextValue stores the value associated with key to context of connection.
529+
func (cc *ClientConn) SetContextValue(key interface{}, val interface{}) {
530+
cc.session.SetContextValue(key, val)
531+
}

udp/session.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func NewSession(
4646
return s
4747
}
4848

49+
// SetContextValue stores the value associated with key to context of connection.
4950
func (s *Session) SetContextValue(key interface{}, val interface{}) {
5051
s.mutex.Lock()
5152
defer s.mutex.Unlock()

0 commit comments

Comments
 (0)