Skip to content

Commit 167b5d3

Browse files
authored
Merge pull request #348 from xssnick/dev-14
v1.14.1
2 parents 89cc955 + 8586cbd commit 167b5d3

File tree

14 files changed

+459
-126
lines changed

14 files changed

+459
-126
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![Based on TON][ton-svg]][ton]
66
[![Telegram Channel][tgc-svg]][tg-channel]
7-
![Coverage](https://img.shields.io/badge/Coverage-69.7%25-yellow)
7+
![Coverage](https://img.shields.io/badge/Coverage-69.5%25-yellow)
88

99
Golang library for interacting with TON blockchain.
1010

adnl/address/address.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
func init() {
99
tl.Register(UDP{}, "adnl.address.udp ip:int port:int = adnl.Address")
10+
tl.Register(UDP6{}, "adnl.address.udp6 ip:int128 port:int = adnl.Address")
1011
tl.Register(List{}, "adnl.addressList addrs:(vector adnl.Address) version:int reinit_date:int priority:int expire_at:int = adnl.AddressList")
1112
}
1213

@@ -15,8 +16,13 @@ type UDP struct {
1516
Port int32 `tl:"int"`
1617
}
1718

19+
type UDP6 struct {
20+
IP net.IP `tl:"int128"`
21+
Port int32 `tl:"int"`
22+
}
23+
1824
type List struct {
19-
Addresses []*UDP `tl:"vector struct boxed"`
25+
Addresses []*UDP `tl:"vector struct boxed"` // TODO: v6 too
2026
Version int32 `tl:"int"`
2127
ReinitDate int32 `tl:"int"`
2228
Priority int32 `tl:"int"`

adnl/adnl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ func (a *ADNL) send(buf []byte) error {
689689
// not close on io timeout because it can be triggered by network overload
690690
if !strings.Contains(err.Error(), "i/o timeout") {
691691
// it should trigger disconnect handler in read routine
692-
a.writer.Close()
692+
a.Close()
693693
}
694694
return err
695695
} else if n != len(buf) {

adnl/conn.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ func newWriter(writer func(p []byte, deadline time.Time) (err error), close func
2525
}
2626
}
2727

28+
var ErrPeerConnClosed = errors.New("peer connection was closed")
29+
2830
func (c *clientConn) Write(b []byte, deadline time.Time) (n int, err error) {
2931
select {
3032
case <-c.closer:
31-
return 0, fmt.Errorf("connection was closed")
33+
return 0, ErrPeerConnClosed
3234
default:
3335
}
3436

adnl/gateway.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ func NewGatewayWithNetManager(key ed25519.PrivateKey, reader NetManager) *Gatewa
125125
var PacketsBufferSize = 128 * 1024
126126

127127
var DefaultListener = func(addr string) (net.PacketConn, error) {
128-
// since ip field in adnl accept only 4 bytes, we cannot fully support v6 right now
129-
lp, err := net.ListenPacket("udp4", addr)
128+
lp, err := net.ListenPacket("udp", addr)
130129
if err != nil {
131130
return nil, err
132131
}
@@ -565,7 +564,9 @@ func (p *peerConn) SetDisconnectHandler(handler func(addr string, key ed25519.Pu
565564
p.server.mx.Unlock()
566565

567566
if handler != nil {
568-
handler(addr, key)
567+
// run it async to avoid potential deadlock issues in user code
568+
// in case closed under lock, and the same lock is used in handler
569+
go handler(addr, key)
569570
}
570571
})
571572
}

adnl/overlay/manager-rldp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
type RLDP interface {
1414
GetADNL() rldp.ADNL
15+
GetRateInfo() (left int64, total int64)
1516
Close()
1617
DoQuery(ctx context.Context, maxAnswerSize uint64, query, result tl.Serializable) error
1718
DoQueryAsync(ctx context.Context, maxAnswerSize uint64, id []byte, query tl.Serializable, result chan<- rldp.AsyncQueryResult) error

adnl/rldp/bucket.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func NewTokenBucket(rate int64, peerName string) *TokenBucket {
2626
}
2727

2828
func (tb *TokenBucket) SetRate(pps int64) {
29-
if pps < 50 {
30-
pps = 50
29+
if pps < 128 {
30+
pps = 128
3131
} else if pps > 5000000 {
3232
pps = 5000000
3333
}

0 commit comments

Comments
 (0)