Decode extracts file from IRC DCC DATA channel
()
| 65 | |
| 66 | // Decode extracts file from IRC DCC DATA channel |
| 67 | func (i *ircDCCDataReader) Decode() { |
| 68 | // Check if this connection matches a tracked DCC connection |
| 69 | keys := []string{ |
| 70 | fmt.Sprintf("%s:%d", i.conversation.ServerIP, i.conversation.ServerPort), |
| 71 | fmt.Sprintf("%s:%d", i.conversation.ClientIP, i.conversation.ClientPort), |
| 72 | } |
| 73 | |
| 74 | var connInfo *IRCDCCConnection |
| 75 | var found bool |
| 76 | var matchedKey string |
| 77 | |
| 78 | for _, key := range keys { |
| 79 | connInfo, found = CheckDCCConnection(key) |
| 80 | if found { |
| 81 | matchedKey = key |
| 82 | break |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if !found { |
| 87 | // Not a tracked DCC connection |
| 88 | return |
| 89 | } |
| 90 | |
| 91 | ircLog.Info("Processing IRC DCC DATA channel", |
| 92 | zap.String("filename", connInfo.Filename), |
| 93 | zap.String("type", connInfo.Type), |
| 94 | zap.Int64("expectedSize", connInfo.Filesize), |
| 95 | zap.String("ident", i.conversation.Ident), |
| 96 | ) |
| 97 | |
| 98 | // DCC SEND: sender connects to receiver |
| 99 | // Data flows from sender (collect all data, typically from one direction) |
| 100 | var fileData []byte |
| 101 | |
| 102 | // Extract all data from the connection |
| 103 | // DCC transfers are typically unidirectional |
| 104 | for _, fragment := range i.conversation.Data { |
| 105 | fileData = append(fileData, fragment.Raw()...) |
| 106 | } |
| 107 | |
| 108 | if len(fileData) == 0 { |
| 109 | ircLog.Warn("No data in IRC DCC channel", |
| 110 | zap.String("ident", i.conversation.Ident), |
| 111 | ) |
| 112 | RemoveDCCConnection(matchedKey) |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | ircLog.Info("Extracting IRC DCC file", |
| 117 | zap.String("filename", connInfo.Filename), |
| 118 | zap.Int("dataSize", len(fileData)), |
| 119 | zap.Int64("expectedSize", connInfo.Filesize), |
| 120 | zap.String("ident", i.conversation.Ident), |
| 121 | ) |
| 122 | |
| 123 | // Extract file |
| 124 | err := ExtractDCCDataChannel(i.conversation, fileData, connInfo) |
nothing calls this directly
no test coverage detected