| 917 | } |
| 918 | |
| 919 | func (c *rawConnection) shouldCompressMessage(msg proto.Message) bool { |
| 920 | switch c.compression { |
| 921 | case CompressionNever: |
| 922 | return false |
| 923 | |
| 924 | case CompressionAlways: |
| 925 | // Use compression for large enough messages |
| 926 | return proto.Size(msg) >= compressionThreshold |
| 927 | |
| 928 | case CompressionMetadata: |
| 929 | _, isResponse := msg.(*bep.Response) |
| 930 | // Compress if it's large enough and not a response message |
| 931 | return !isResponse && proto.Size(msg) >= compressionThreshold |
| 932 | |
| 933 | default: |
| 934 | panic("unknown compression setting") |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | // Close is called when the connection is regularly closed and thus the Close |
| 939 | // BEP message is sent before terminating the actual connection. The error |