@@ -14,9 +14,10 @@ import (
1414)
1515
1616type Pipe struct {
17- id string
18- sConn net.Conn
19- rConn net.Conn
17+ id string
18+ sConn net.Conn
19+ rConn net.Conn
20+ bufferSize int
2021
2122 rAddr * net.TCPAddr
2223 sMailAddr []byte
@@ -29,6 +30,8 @@ type Pipe struct {
2930 locked bool
3031 blocker chan interface {}
3132
33+ isWaitedStarttlsRes bool
34+
3235 timeAtConnected time.Time
3336 timeAtDataStarting time.Time
3437
@@ -46,7 +49,6 @@ const (
4649 mailFromPrefix string = "MAIL FROM:<"
4750 rcptToPrefix string = "RCPT TO:<"
4851 mailRegex string = `[A-z0-9.!#$%&'*+\-/=?^_\{|}~]{1,64}@[A-z0-9.\-]{1,255}`
49- bufferSize int = 32 * 1024
5052 crlf string = "\r \n "
5153 mailHeaderEnd string = crlf + crlf
5254
@@ -91,6 +93,7 @@ func (p *Pipe) mediateOnUpstream(b []byte, i int) ([]byte, int, bool) {
9193 if ! p .tls && p .readytls {
9294 p .locked = true
9395 er := p .starttls ()
96+ p .isWaitedStarttlsRes = true
9497 if er != nil {
9598 go p .afterCommHook ([]byte (fmt .Sprintf ("starttls error: %s" , er .Error ())), pxyToDst )
9699 }
@@ -123,15 +126,15 @@ func (p *Pipe) mediateOnDownstream(b []byte, i int) ([]byte, int, bool) {
123126 }
124127 }
125128
126- // time before email input
127- p .setTimeAtDataStarting (b )
128-
129- // remove buffering ready response
130- if p .tls && ! p .readytls && p .locked {
131- // continue
129+ // remove buffering "220 2.0.0 Ready to start TLS" response
130+ if p .isWaitedStarttlsRes {
131+ p .isWaitedStarttlsRes = false
132132 return b , i , true
133133 }
134134
135+ // time before email input
136+ p .setTimeAtDataStarting (b )
137+
135138 if p .isResponseOfEHLOWithoutStartTLS (b ) {
136139 go p .afterCommHook (data , pxyToSrc )
137140 } else {
@@ -213,7 +216,7 @@ func (p *Pipe) dst(d Flow) net.Conn {
213216}
214217
215218func (p * Pipe ) copy (dr Flow , fn Mediator ) (written int64 , err error ) {
216- size := bufferSize
219+ size := p . bufferSize
217220 src , ok := p .src (dr ).(io.Reader )
218221 if ! ok {
219222 err = fmt .Errorf ("io.Reader cast error" )
@@ -226,7 +229,7 @@ func (p *Pipe) copy(dr Flow, fn Mediator) (written int64, err error) {
226229 }
227230 go p .afterCommHook ([]byte (fmt .Sprintf ("io.Reader size: %d" , size )), onPxy )
228231 }
229- buf := make ([]byte , bufferSize )
232+ buf := make ([]byte , p . bufferSize )
230233
231234 for {
232235 var isContinue bool
@@ -284,7 +287,7 @@ func (p *Pipe) starttls() error {
284287}
285288
286289func (p * Pipe ) readReceiverConn () error {
287- buf := make ([]byte , bufferSize )
290+ buf := make ([]byte , 64 * 1024 )
288291 i , err := p .rConn .Read (buf )
289292 if err != nil {
290293 return err
0 commit comments