Skip to content

Commit

Permalink
update writefile (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Nov 27, 2023
1 parent 42284f0 commit e40b326
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ const DirMode = 0644
const BufferSize = 64 * SIZE_1KiB
const SegmentSize = 64 * SIZE_1MiB
const FragmentSize = 16 * SIZE_1MiB

const ZeroFileHash_16M = "080acf35a507ac9849cfcba47dc2ad83e01b75663a516279c8b9d243b719643e"
17 changes: 17 additions & 0 deletions core/writefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ func (e *WriteFileProtocol) onWriteFileRequest(s network.Stream) {

fpath := filepath.Join(dir, data.Datahash)

if data.Datahash == ZeroFileHash_16M {
f, err := os.Create(fpath)
if err != nil {
s.Reset()
return
}
defer f.Close()
_, err = f.Write(make([]byte, FragmentSize))
if err != nil {
s.Reset()
return
}
resp.Code = P2PResponseFinish
e.SendProtoMessage(s.Conn().RemotePeer(), protocol.ID(e.ProtocolPrefix+writeFileResponse), resp)
return
}

fstat, err = os.Stat(fpath)
if err == nil {
size = fstat.Size()
Expand Down

0 comments on commit e40b326

Please sign in to comment.