move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package tgtest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/crypto"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/exchange"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/proto/codec"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/transport"
|
||||
)
|
||||
|
||||
type exchangeConn struct {
|
||||
transport.Conn
|
||||
}
|
||||
|
||||
func (e exchangeConn) Recv(ctx context.Context, b *bin.Buffer) error {
|
||||
for {
|
||||
if err := e.Conn.Recv(ctx, b); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var authKeyID [8]byte
|
||||
if err := b.PeekN(authKeyID[:], len(authKeyID)); err != nil {
|
||||
return errors.Wrap(err, "peek id")
|
||||
}
|
||||
if authKeyID != [8]byte{} {
|
||||
// TODO(tdakkota): what if client send registered auth key during key exchange?
|
||||
buf := bin.Buffer{}
|
||||
buf.PutInt32(-codec.CodeAuthKeyNotFound)
|
||||
|
||||
if err := e.Conn.Send(ctx, &buf); err != nil {
|
||||
return errors.Wrap(err, "send")
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// exchange starts MTProto key exchange.
|
||||
func (s *Server) exchange(ctx context.Context, conn transport.Conn) (crypto.AuthKey, error) {
|
||||
r, err := exchange.NewExchanger(conn, s.dcID).
|
||||
WithClock(s.clock).
|
||||
WithLogger(s.log.Named("exchange")).
|
||||
WithRand(s.cipher.Rand()).
|
||||
Server(s.key).Run(ctx)
|
||||
if err != nil {
|
||||
return crypto.AuthKey{}, err
|
||||
}
|
||||
|
||||
return r.Key, nil
|
||||
}
|
||||
Reference in New Issue
Block a user