package exchange
import (
"io"
"time"
"go.uber.org/zap"
"github.com/gotd/td/clock"
"github.com/gotd/td/internal/crypto"
"github.com/gotd/td/internal/proto"
"github.com/gotd/td/transport"
)
const DefaultTimeout = 1 * time .Minute
type Exchanger struct {
conn transport .Conn
clock clock .Clock
rand io .Reader
log *zap .Logger
timeout time .Duration
dc int
}
func (e Exchanger ) WithClock (c clock .Clock ) Exchanger {
e .clock = c
return e
}
func (e Exchanger ) WithRand (reader io .Reader ) Exchanger {
e .rand = reader
return e
}
func (e Exchanger ) WithLogger (log *zap .Logger ) Exchanger {
e .log = log
return e
}
func (e Exchanger ) WithTimeout (timeout time .Duration ) Exchanger {
e .timeout = timeout
return e
}
func NewExchanger (conn transport .Conn , dc int ) Exchanger {
return Exchanger {
conn : conn ,
clock : clock .System ,
rand : crypto .DefaultRand (),
log : zap .NewNop (),
timeout : DefaultTimeout ,
dc : dc ,
}
}
func (e Exchanger ) unencryptedWriter (input , output proto .MessageType ) unencryptedWriter {
return unencryptedWriter {
clock : e .clock ,
conn : e .conn ,
timeout : e .timeout ,
input : input ,
output : output ,
}
}
func (e Exchanger ) Client (keys []PublicKey ) ClientExchange {
return ClientExchange {
unencryptedWriter : e .unencryptedWriter (
proto .MessageServerResponse ,
proto .MessageFromClient ,
),
rand : e .rand ,
log : e .log ,
keys : keys ,
dc : e .dc ,
}
}
func (e Exchanger ) Server (key PrivateKey ) ServerExchange {
return ServerExchange {
unencryptedWriter : e .unencryptedWriter (
proto .MessageFromClient ,
proto .MessageServerResponse ,
),
rand : e .rand ,
log : e .log ,
rng : TestServerRNG {rand : e .rand },
key : key ,
dc : e .dc ,
}
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .