| 874 | ) |
| 875 | |
| 876 | func (t *http2Server) handlePing(f *http2.PingFrame) { |
| 877 | if f.IsAck() { |
| 878 | if f.Data == goAwayPing.data && t.drainEvent != nil { |
| 879 | t.drainEvent.Fire() |
| 880 | return |
| 881 | } |
| 882 | // Maybe it's a BDP ping. |
| 883 | if t.bdpEst != nil { |
| 884 | t.bdpEst.calculate(f.Data) |
| 885 | } |
| 886 | return |
| 887 | } |
| 888 | pingAck := &ping{ack: true} |
| 889 | copy(pingAck.data[:], f.Data[:]) |
| 890 | t.controlBuf.put(pingAck) |
| 891 | |
| 892 | now := time.Now() |
| 893 | defer func() { |
| 894 | t.lastPingAt = now |
| 895 | }() |
| 896 | // A reset ping strikes means that we don't need to check for policy |
| 897 | // violation for this ping and the pingStrikes counter should be set |
| 898 | // to 0. |
| 899 | if atomic.CompareAndSwapUint32(&t.resetPingStrikes, 1, 0) { |
| 900 | t.pingStrikes = 0 |
| 901 | return |
| 902 | } |
| 903 | t.mu.Lock() |
| 904 | ns := len(t.activeStreams) |
| 905 | t.mu.Unlock() |
| 906 | if ns < 1 && !t.kep.PermitWithoutStream { |
| 907 | // Keepalive shouldn't be active thus, this new ping should |
| 908 | // have come after at least defaultPingTimeout. |
| 909 | if t.lastPingAt.Add(defaultPingTimeout).After(now) { |
| 910 | t.pingStrikes++ |
| 911 | } |
| 912 | } else { |
| 913 | // Check if keepalive policy is respected. |
| 914 | if t.lastPingAt.Add(t.kep.MinTime).After(now) { |
| 915 | t.pingStrikes++ |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if t.pingStrikes > maxPingStrikes { |
| 920 | // Send goaway and close the connection. |
| 921 | t.controlBuf.put(&goAway{code: http2.ErrCodeEnhanceYourCalm, debugData: []byte("too_many_pings"), closeConn: errors.New("got too many pings from the client")}) |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | func (t *http2Server) handleWindowUpdate(f *http2.WindowUpdateFrame) { |
| 926 | t.controlBuf.put(&incomingWindowUpdate{ |