(route string, targetUUID string, identity int)
| 159 | } |
| 160 | |
| 161 | func (file *MyFile) Upload(route string, targetUUID string, identity int) { |
| 162 | var sMessage protocol.Message |
| 163 | if identity == ADMIN { |
| 164 | sMessage = protocol.PrepareAndDecideWhichSProtoToLower(global.G_Component.Conn, global.G_Component.Secret, global.G_Component.UUID) |
| 165 | } else { |
| 166 | sMessage = protocol.PrepareAndDecideWhichSProtoToUpper(global.G_Component.Conn, global.G_Component.Secret, global.G_Component.UUID) |
| 167 | } |
| 168 | |
| 169 | dataHeader := &protocol.Header{ |
| 170 | Sender: global.G_Component.UUID, |
| 171 | Accepter: targetUUID, |
| 172 | MessageType: protocol.FILEDATA, |
| 173 | RouteLen: uint32(len([]byte(route))), |
| 174 | Route: route, |
| 175 | } |
| 176 | |
| 177 | errHeader := &protocol.Header{ |
| 178 | Sender: global.G_Component.UUID, |
| 179 | Accepter: targetUUID, |
| 180 | MessageType: protocol.FILEERR, |
| 181 | RouteLen: uint32(len([]byte(route))), |
| 182 | Route: route, |
| 183 | } |
| 184 | |
| 185 | fileErrMess := &protocol.FileErr{ |
| 186 | Error: 1, |
| 187 | } |
| 188 | |
| 189 | if identity == ADMIN { |
| 190 | fmt.Println("\n[*] File transmitting, please wait...") |
| 191 | file.StatusChan <- &Status{Stat: START} |
| 192 | } |
| 193 | |
| 194 | buffer := make([]byte, 30720) |
| 195 | |
| 196 | defer func() { |
| 197 | if identity == ADMIN { |
| 198 | file.StatusChan <- &Status{Stat: DONE} |
| 199 | } |
| 200 | runtime.GC() |
| 201 | file.Handler.Close() |
| 202 | }() |
| 203 | |
| 204 | for { |
| 205 | length, err := file.Handler.Read(buffer) |
| 206 | if err != nil && err != io.EOF { |
| 207 | protocol.ConstructMessage(sMessage, errHeader, fileErrMess, false) |
| 208 | sMessage.SendMessage() |
| 209 | return |
| 210 | } else if err != nil && err == io.EOF { |
| 211 | return |
| 212 | } |
| 213 | |
| 214 | fileDataMess := &protocol.FileData{ |
| 215 | DataLen: uint64(length), |
| 216 | Data: buffer[:length], |
| 217 | } |
| 218 |
no test coverage detected