anchor.diff:      ensure_random_file(File2),
       ok.
   
  +%% Create a broken version of Fn, if it do not exist.
  +ensure_broken_file(Fn, BrokenFn) ->
  +    case filelib:is_regular(BrokenFn) of
  +	true  -> ok;
  +	false -> file:copy(Fn, BrokenFn), broke_file(BrokenFn)
  +    end.
  +
  +
  +broke_file(BrokenFn) ->
  +    random:seed(now()),
  +    {ok, Fd} = file:open(BrokenFn, [write, binary, append]),
  +    {ok, TotalSize} = file:position(Fd, eof),
  +    %% Modify 10 chunks in the file.
  +    write_bad_chunks(Fd, TotalSize, 10),
  +    file:close(Fd).
  +
  +
  +write_bad_chunks(_Fd, _TotalSize, 0) ->
  +    ok;
  +write_bad_chunks(Fd, TotalSize, N) ->
  +    write_bad_chunk(Fd, TotalSize),
  +    write_bad_chunks(Fd, TotalSize, N-1).
  +
  +write_bad_chunk(Fd, TotalSize) ->
  +    %% Len :: 1 .. 16#FFFF.
  +    Len  = random:uniform(16#FFFF),
  +    From = random:uniform(TotalSize - Len),
  +    file:pwrite(Fd, From, crypto:rand_bytes(Len)).
  +
  +
  +
   
   sha1_file(F) ->
       Ctx = crypto:sha_init(),
  
positive.code:     BadUDPDirTorrentFn = filename:join([AutoDir, "dir2x30m-bad-udp.torrent"]),
  
      ensure_random_file(Fn),
      ensure_random_dir(Dir),
  
      ensure_torrent_file(Fn,  HTTPTorrentFn, "http://localhost:6969/announce"),
  
negative.code:     Directory = ?config(data_dir, Config),
  %%  file:set_cwd(Directory),
      ct:pal("Data directory: ~s~n", [Directory]),
      %% Autogenerated random files.
      AutoDir = filename:join(Directory, autogen),
      %% This is a directory, with partically downloaded versions of files
      %% from AutoDir.
      BrokenDir = filename:join(AutoDir, broken),
      file:make_dir(AutoDir),
      file:make_dir(BrokenDir),
      Fn                 = filename:join([AutoDir, "file30m.random"]),
      BrokenFn           = filename:join([BrokenDir, "file30m.random"]),
      Dir                = filename:join([AutoDir, "dir2x30m"]),
      DumpTorrentFn      = filename:join([AutoDir, "file30m-trackerless.torrent"]),
      HTTPTorrentFn      = filename:join([AutoDir, "file30m-http.torrent"]),
  