diff --git a/core/config.go b/core/config.go index 56bb582..7b8a1ad 100644 --- a/core/config.go +++ b/core/config.go @@ -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" diff --git a/core/writefile.go b/core/writefile.go index 7759934..08c9a78 100644 --- a/core/writefile.go +++ b/core/writefile.go @@ -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()